Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lsp): Use correct origin selection range #2146

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 44 additions & 21 deletions compiler/src/language_server/goto.re
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ let send_no_result = (~id: Protocol.message_id) => {
let send_location_link =
(
~id: Protocol.message_id,
~range: Protocol.range,
~origin_range: Protocol.range,
~target_uri: Protocol.uri,
target_range: Protocol.range,
~target_range: Protocol.range,
) => {
Protocol.response(
~id,
Protocol.location_link_to_yojson({
origin_selection_range: range,
origin_selection_range: origin_range,
target_uri,
target_range,
target_selection_range: target_range,
Expand All @@ -52,7 +52,8 @@ type check_position =
let rec find_location =
(
~check_position=Forward,
get_location: list(Sourcetree.node) => option(Location.t),
get_location:
list(Sourcetree.node) => option((Location.t, Location.t)),
sourcetree: Sourcetree.sourcetree,
position: Protocol.position,
) => {
Expand All @@ -61,9 +62,9 @@ let rec find_location =
let result =
switch (get_location(results)) {
| None => None
| Some(loc) =>
let uri = Utils.filename_to_uri(loc.loc_start.pos_fname);
Some((loc, uri));
| Some((origin_loc, target_loc)) =>
let uri = Utils.filename_to_uri(target_loc.loc_start.pos_fname);
Some((origin_loc, target_loc, uri));
};
switch (result) {
| None =>
Expand All @@ -79,7 +80,7 @@ let rec find_location =
} else {
None;
}
| Some((loc, uri)) => result
| Some(_) => result
};
};

Expand All @@ -99,22 +100,44 @@ let process =
| Definition => (
results => {
switch (results) {
| [Sourcetree.Value({definition}), ..._]
| [Pattern({definition}), ..._]
| [Type({definition}), ..._]
| [Declaration({definition}), ..._]
| [Exception({definition}), ..._]
| [Module({definition}), ..._] => definition
| [Sourcetree.Value({loc, definition: Some(definition)}), ..._]
| [
Pattern({
pattern: {pat_loc: loc},
definition: Some(definition),
}),
..._,
]
| [
Type({
core_type: {ctyp_loc: loc},
definition: Some(definition),
}),
..._,
]
| [Declaration({loc, definition: Some(definition)}), ..._]
| [Exception({loc, definition: Some(definition)}), ..._]
| [Module({loc, definition: Some(definition)}), ..._] =>
Some((loc, definition))
| _ => None
};
}
)
| TypeDefinition => (
results => {
switch (results) {
| [Value({env, value_type: type_expr}), ..._] =>
Env.get_type_definition_loc(type_expr, env)
| [Pattern({definition}), ..._] => definition
| [Value({loc, env, value_type: type_expr}), ..._] =>
Option.bind(Env.get_type_definition_loc(type_expr, env), l =>
Some((loc, l))
)
| [
Pattern({
pattern: {pat_loc: loc},
definition: Some(definition),
}),
..._,
] =>
Some((loc, definition))
| _ => None
};
}
Expand All @@ -124,12 +147,12 @@ let process =
let result = find_location(get_location, sourcetree, params.position);
switch (result) {
| None => send_no_result(~id)
| Some((loc, uri)) =>
| Some((origin_loc, target_loc, target_uri)) =>
send_location_link(
~id,
~range=Utils.loc_to_range(loc),
~target_uri=uri,
Utils.loc_to_range(loc),
~origin_range=Utils.loc_to_range(origin_loc),
~target_uri,
~target_range=Utils.loc_to_range(target_loc),
)
};
};
Expand Down
Loading