Skip to content

Commit 8743158

Browse files
GearsDatapackslpil
authored andcommitted
Fix go to definition for unqualified functions
1 parent 65c2efb commit 8743158

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
two constructors of the same name were created.
1717
([Surya Rose](https://github.com/GearsDatapacks))
1818

19+
- Fixed a bug where jumping to the definition of an unqualified function would
20+
produce the correct location, but remain in the same file.
21+
([Surya Rose](https://github.com/gearsdatapacks))
22+
1923
## v1.4.1 - 2024-08-04
2024

2125
### Bug Fixes

compiler-core/src/language_server/tests/definition.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,41 @@ fn main() {
906906
)
907907
}
908908

909+
#[test]
910+
fn goto_definition_unqualified_function() {
911+
let code = "
912+
import wibble.{wobble}
913+
fn main() {
914+
wobble()
915+
}
916+
";
917+
918+
assert_eq!(
919+
definition(
920+
TestProject::for_source(code).add_module("wibble", "pub fn wobble() {}"),
921+
Position::new(3, 5)
922+
),
923+
Some(Location {
924+
uri: Url::from_file_path(Utf8PathBuf::from(if cfg!(target_family = "windows") {
925+
r"\\?\C:\src\wibble.gleam"
926+
} else {
927+
"/src/wibble.gleam"
928+
}))
929+
.unwrap(),
930+
range: Range {
931+
start: Position {
932+
line: 0,
933+
character: 0
934+
},
935+
end: Position {
936+
line: 0,
937+
character: 15
938+
}
939+
}
940+
})
941+
)
942+
}
943+
909944
#[test]
910945
fn goto_definition_import_unqualified_type() {
911946
let code = "

compiler-core/src/type_.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,9 @@ impl ValueConstructor {
963963
}
964964
| ValueConstructorVariant::ModuleConstant {
965965
location, module, ..
966+
}
967+
| ValueConstructorVariant::ModuleFn {
968+
location, module, ..
966969
} => DefinitionLocation {
967970
module: Some(module.as_str()),
968971
span: *location,
@@ -973,8 +976,7 @@ impl ValueConstructor {
973976
span: literal.location(),
974977
},
975978

976-
ValueConstructorVariant::ModuleFn { location, .. }
977-
| ValueConstructorVariant::LocalVariable { location } => DefinitionLocation {
979+
ValueConstructorVariant::LocalVariable { location } => DefinitionLocation {
978980
module: None,
979981
span: *location,
980982
},

0 commit comments

Comments
 (0)