Add import definition & fix bug

This commit is contained in:
ef3d0c3e 2024-11-19 12:44:29 +01:00
parent 4c5e888bd9
commit 78509f7ae5
2 changed files with 16 additions and 6 deletions

View file

@ -10,6 +10,7 @@ use crate::parser::rule::RegexRule;
use crate::parser::source::SourceFile;
use crate::parser::source::Token;
use ariadne::Fmt;
use lsp::definition;
use regex::Captures;
use regex::Regex;
use std::rc::Rc;
@ -160,10 +161,12 @@ impl RegexRule for ImportRule {
};
state.with_state(|new_state| {
let (import_doc, _) =
new_state
.parser
.parse(new_state, import, Some(document), ParseMode::default());
let (import_doc, _) = new_state.parser.parse(
new_state,
import.clone(),
Some(document),
ParseMode::default(),
);
document.merge(import_doc.content(), import_doc.scope(), Some(&import_as));
});
@ -202,6 +205,9 @@ impl RegexRule for ImportRule {
sems.add(path, tokens.import_path);
}
// Definition point to start of imported document
definition::from_source(token, &Token::new(0..0, import), &state.shared.lsp);
reports
}
}

View file

@ -86,8 +86,12 @@ fn from_source_impl(
};
// Add definition
let target_path = std::fs::canonicalize(orignal_target.0.name().as_str()).unwrap();
let uri = Url::from_file_path(target_path).unwrap();
let uri = if orignal_target.0.name().starts_with("file://") {
Url::try_from(orignal_target.0.name().as_str()).unwrap()
} else {
let target_path = std::fs::canonicalize(orignal_target.0.name().as_str()).unwrap();
Url::from_file_path(target_path).unwrap()
};
db.push((
Location {
uri,