Add import definition & fix bug
This commit is contained in:
parent
4c5e888bd9
commit
78509f7ae5
2 changed files with 16 additions and 6 deletions
|
@ -10,6 +10,7 @@ use crate::parser::rule::RegexRule;
|
||||||
use crate::parser::source::SourceFile;
|
use crate::parser::source::SourceFile;
|
||||||
use crate::parser::source::Token;
|
use crate::parser::source::Token;
|
||||||
use ariadne::Fmt;
|
use ariadne::Fmt;
|
||||||
|
use lsp::definition;
|
||||||
use regex::Captures;
|
use regex::Captures;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
@ -160,10 +161,12 @@ impl RegexRule for ImportRule {
|
||||||
};
|
};
|
||||||
|
|
||||||
state.with_state(|new_state| {
|
state.with_state(|new_state| {
|
||||||
let (import_doc, _) =
|
let (import_doc, _) = new_state.parser.parse(
|
||||||
new_state
|
new_state,
|
||||||
.parser
|
import.clone(),
|
||||||
.parse(new_state, import, Some(document), ParseMode::default());
|
Some(document),
|
||||||
|
ParseMode::default(),
|
||||||
|
);
|
||||||
document.merge(import_doc.content(), import_doc.scope(), Some(&import_as));
|
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);
|
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
|
reports
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,8 +86,12 @@ fn from_source_impl(
|
||||||
};
|
};
|
||||||
|
|
||||||
// Add definition
|
// Add definition
|
||||||
let target_path = std::fs::canonicalize(orignal_target.0.name().as_str()).unwrap();
|
let uri = if orignal_target.0.name().starts_with("file://") {
|
||||||
let uri = Url::from_file_path(target_path).unwrap();
|
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((
|
db.push((
|
||||||
Location {
|
Location {
|
||||||
uri,
|
uri,
|
||||||
|
|
Loading…
Reference in a new issue