Skip to content

Commit ab3dde8

Browse files
authored
fix(lsp): Use correct origin selection range (#2146)
1 parent 960fadd commit ab3dde8

File tree

1 file changed

+44
-21
lines changed
  • compiler/src/language_server

1 file changed

+44
-21
lines changed

compiler/src/language_server/goto.re

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ let send_no_result = (~id: Protocol.message_id) => {
3030
let send_location_link =
3131
(
3232
~id: Protocol.message_id,
33-
~range: Protocol.range,
33+
~origin_range: Protocol.range,
3434
~target_uri: Protocol.uri,
35-
target_range: Protocol.range,
35+
~target_range: Protocol.range,
3636
) => {
3737
Protocol.response(
3838
~id,
3939
Protocol.location_link_to_yojson({
40-
origin_selection_range: range,
40+
origin_selection_range: origin_range,
4141
target_uri,
4242
target_range,
4343
target_selection_range: target_range,
@@ -52,7 +52,8 @@ type check_position =
5252
let rec find_location =
5353
(
5454
~check_position=Forward,
55-
get_location: list(Sourcetree.node) => option(Location.t),
55+
get_location:
56+
list(Sourcetree.node) => option((Location.t, Location.t)),
5657
sourcetree: Sourcetree.sourcetree,
5758
position: Protocol.position,
5859
) => {
@@ -61,9 +62,9 @@ let rec find_location =
6162
let result =
6263
switch (get_location(results)) {
6364
| None => None
64-
| Some(loc) =>
65-
let uri = Utils.filename_to_uri(loc.loc_start.pos_fname);
66-
Some((loc, uri));
65+
| Some((origin_loc, target_loc)) =>
66+
let uri = Utils.filename_to_uri(target_loc.loc_start.pos_fname);
67+
Some((origin_loc, target_loc, uri));
6768
};
6869
switch (result) {
6970
| None =>
@@ -79,7 +80,7 @@ let rec find_location =
7980
} else {
8081
None;
8182
}
82-
| Some((loc, uri)) => result
83+
| Some(_) => result
8384
};
8485
};
8586

@@ -99,22 +100,44 @@ let process =
99100
| Definition => (
100101
results => {
101102
switch (results) {
102-
| [Sourcetree.Value({definition}), ..._]
103-
| [Pattern({definition}), ..._]
104-
| [Type({definition}), ..._]
105-
| [Declaration({definition}), ..._]
106-
| [Exception({definition}), ..._]
107-
| [Module({definition}), ..._] => definition
103+
| [Sourcetree.Value({loc, definition: Some(definition)}), ..._]
104+
| [
105+
Pattern({
106+
pattern: {pat_loc: loc},
107+
definition: Some(definition),
108+
}),
109+
..._,
110+
]
111+
| [
112+
Type({
113+
core_type: {ctyp_loc: loc},
114+
definition: Some(definition),
115+
}),
116+
..._,
117+
]
118+
| [Declaration({loc, definition: Some(definition)}), ..._]
119+
| [Exception({loc, definition: Some(definition)}), ..._]
120+
| [Module({loc, definition: Some(definition)}), ..._] =>
121+
Some((loc, definition))
108122
| _ => None
109123
};
110124
}
111125
)
112126
| TypeDefinition => (
113127
results => {
114128
switch (results) {
115-
| [Value({env, value_type: type_expr}), ..._] =>
116-
Env.get_type_definition_loc(type_expr, env)
117-
| [Pattern({definition}), ..._] => definition
129+
| [Value({loc, env, value_type: type_expr}), ..._] =>
130+
Option.bind(Env.get_type_definition_loc(type_expr, env), l =>
131+
Some((loc, l))
132+
)
133+
| [
134+
Pattern({
135+
pattern: {pat_loc: loc},
136+
definition: Some(definition),
137+
}),
138+
..._,
139+
] =>
140+
Some((loc, definition))
118141
| _ => None
119142
};
120143
}
@@ -124,12 +147,12 @@ let process =
124147
let result = find_location(get_location, sourcetree, params.position);
125148
switch (result) {
126149
| None => send_no_result(~id)
127-
| Some((loc, uri)) =>
150+
| Some((origin_loc, target_loc, target_uri)) =>
128151
send_location_link(
129152
~id,
130-
~range=Utils.loc_to_range(loc),
131-
~target_uri=uri,
132-
Utils.loc_to_range(loc),
153+
~origin_range=Utils.loc_to_range(origin_loc),
154+
~target_uri,
155+
~target_range=Utils.loc_to_range(target_loc),
133156
)
134157
};
135158
};

0 commit comments

Comments
 (0)