Skip to content

Commit 23142af

Browse files
committed
chore(els): improve doc highlight, type definition
1 parent a47271e commit 23142af

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

crates/els/doc_highlight.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
3131
if let Some(range) = loc_to_range(vi.def_loc.loc) {
3232
res.push(DocumentHighlight {
3333
range,
34-
kind: Some(DocumentHighlightKind::TEXT),
34+
kind: Some(DocumentHighlightKind::WRITE),
3535
});
3636
}
3737
for reference in self.get_refs_from_abs_loc(&vi.def_loc) {
3838
res.push(DocumentHighlight {
3939
range: reference.range,
40-
kind: Some(DocumentHighlightKind::TEXT),
40+
kind: Some(DocumentHighlightKind::READ),
4141
});
4242
}
4343
}

crates/els/type_definition.rs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
use std::path::Path;
22

3+
use erg_common::set::Set;
34
use erg_common::shared::MappedRwLockReadGuard;
45
use erg_compiler::artifact::BuildRunnable;
56
use erg_compiler::erg_parser::parse::Parsable;
67

8+
use erg_compiler::ty::{HasType, Type};
79
use lsp_types::request::{GotoTypeDefinitionParams, GotoTypeDefinitionResponse};
8-
use lsp_types::{GotoDefinitionResponse, Position, Url};
10+
use lsp_types::{GotoDefinitionResponse, Location, Position, Url};
911

1012
use crate::server::{ELSResult, RedirectableStdout, Server};
1113
use crate::util::{self, NormalizedUrl};
@@ -21,10 +23,7 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
2123
Ok(self.get_type_def(&uri, pos))
2224
}
2325

24-
fn get_type_def(&self, uri: &NormalizedUrl, pos: Position) -> Option<GotoDefinitionResponse> {
25-
let visitor = self.get_visitor(uri)?;
26-
let tok = self.file_cache.get_symbol(uri, pos)?;
27-
let typ = &visitor.get_info(&tok)?.t;
26+
fn make_type_definition(&self, uri: &NormalizedUrl, typ: &Type) -> Option<Location> {
2827
let path = typ.namespace();
2928
let module = self
3029
.shared
@@ -34,7 +33,26 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
3433
let (_, typ_info) = module.context.get_type_info(typ)?;
3534
let path = typ_info.def_loc.module.as_ref()?;
3635
let def_uri = Url::from_file_path(path).ok()?;
37-
let loc = lsp_types::Location::new(def_uri, util::loc_to_range(typ_info.def_loc.loc)?);
38-
Some(GotoDefinitionResponse::Scalar(loc))
36+
Some(Location::new(
37+
def_uri,
38+
util::loc_to_range(typ_info.def_loc.loc)?,
39+
))
40+
}
41+
42+
fn get_type_def(&self, uri: &NormalizedUrl, pos: Position) -> Option<GotoDefinitionResponse> {
43+
let mut locs = vec![];
44+
let visitor = self.get_visitor(uri)?;
45+
let tok = self.file_cache.get_symbol(uri, pos)?;
46+
let typ = &visitor.get_info(&tok)?.t;
47+
if let Some(loc) = self.make_type_definition(uri, typ) {
48+
locs.push(loc);
49+
}
50+
let typs = typ.inner_ts().into_iter().collect::<Set<_>>();
51+
for typ in typs {
52+
if let Some(loc) = self.make_type_definition(uri, &typ) {
53+
locs.push(loc);
54+
}
55+
}
56+
Some(GotoDefinitionResponse::Array(locs))
3957
}
4058
}

0 commit comments

Comments
 (0)