Add document links for 'resource' expressions

This commit is contained in:
Tad Hardesty 2020-09-19 18:12:28 -07:00
parent 3a17944a66
commit f1def794d0
4 changed files with 19 additions and 9 deletions

View file

@ -30,7 +30,9 @@ pub enum Annotation {
// a macro is called here, which is defined at this location
MacroDefinition(String),
MacroUse(String, Location),
Include(std::path::PathBuf),
Resource(std::path::PathBuf),
// error annotations, mostly for autocompletion
ScopedMissingIdent(Vec<String>), // when a . is followed by a non-ident

View file

@ -2043,7 +2043,10 @@ impl<'ctx, 'an, 'inp> Parser<'ctx, 'an, 'inp> {
// term :: str_lit | num_lit
Token::String(val) => Term::String(val),
Token::Resource(val) => Term::Resource(val),
Token::Resource(val) => {
self.annotate_precise(start..start.add_columns(2 + val.len() as u16), || Annotation::Resource(val.as_str().into()));
Term::Resource(val)
},
Token::Int(val) => Term::Int(val),
Token::Float(val) => Term::Float(val),

View file

@ -783,13 +783,9 @@ impl<'ctx> Preprocessor<'ctx> {
};
if let Some(annotations) = self.annotations.as_mut() {
let mut full_path = candidate.clone();
if full_path.is_relative() {
full_path = std::env::current_dir().expect("couldn't get current dir").join(&full_path);
}
annotations.insert(
include_loc .. include_loc.add_columns(2 + path_str.len() as u16),
Annotation::Include(full_path));
Annotation::Include(candidate.clone()));
}
match file_type {

View file

@ -1855,17 +1855,26 @@ handle_method_call! {
}
on DocumentLinkRequest(&mut self, params) {
let (_, _, annotations) = self.get_annotations(&params.text_document.uri)?;
let (_, file_id, annotations) = self.get_annotations(&params.text_document.uri)?;
if annotations.is_empty() {
None
} else {
let mut results = Vec::new();
for (span, annotation) in annotations.iter() {
if span.start.file != file_id {
continue;
}
match annotation {
Annotation::Include(pathbuf) => {
Annotation::Include(path) |
Annotation::Resource(path) => {
let pathbuf = if path.is_relative() {
std::env::current_dir().map_err(invalid_request)?.join(&path)
} else {
path.to_owned()
};
results.push(DocumentLink {
range: span_to_range(span.start..span.end.add_columns(1)),
target: Some(path_to_url(pathbuf.clone())?),
target: Some(path_to_url(pathbuf)?),
tooltip: None,
data: None,
});