diff --git a/src/dreammaker/annotation.rs b/src/dreammaker/annotation.rs index 9db83c29..e3f5ff46 100644 --- a/src/dreammaker/annotation.rs +++ b/src/dreammaker/annotation.rs @@ -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), // when a . is followed by a non-ident diff --git a/src/dreammaker/parser.rs b/src/dreammaker/parser.rs index 92591614..99035621 100644 --- a/src/dreammaker/parser.rs +++ b/src/dreammaker/parser.rs @@ -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), diff --git a/src/dreammaker/preprocessor.rs b/src/dreammaker/preprocessor.rs index 614ef00a..86e8d6ee 100644 --- a/src/dreammaker/preprocessor.rs +++ b/src/dreammaker/preprocessor.rs @@ -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 { diff --git a/src/langserver/main.rs b/src/langserver/main.rs index fd71a8a7..15b139e0 100644 --- a/src/langserver/main.rs +++ b/src/langserver/main.rs @@ -1855,17 +1855,26 @@ handle_method_call! { } on DocumentLinkRequest(&mut self, params) { - let (_, _, annotations) = self.get_annotations(¶ms.text_document.uri)?; + let (_, file_id, annotations) = self.get_annotations(¶ms.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, });