Skip to content

Commit

Permalink
Fix go to definition for unqualified functions
Browse files Browse the repository at this point in the history
  • Loading branch information
GearsDatapacks authored and lpil committed Aug 4, 2024
1 parent 65c2efb commit 8743158
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
two constructors of the same name were created.
([Surya Rose](https://github.com/GearsDatapacks))

- Fixed a bug where jumping to the definition of an unqualified function would
produce the correct location, but remain in the same file.
([Surya Rose](https://github.com/gearsdatapacks))

## v1.4.1 - 2024-08-04

### Bug Fixes
Expand Down
35 changes: 35 additions & 0 deletions compiler-core/src/language_server/tests/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,41 @@ fn main() {
)
}

#[test]
fn goto_definition_unqualified_function() {
let code = "
import wibble.{wobble}
fn main() {
wobble()
}
";

assert_eq!(
definition(
TestProject::for_source(code).add_module("wibble", "pub fn wobble() {}"),
Position::new(3, 5)
),
Some(Location {
uri: Url::from_file_path(Utf8PathBuf::from(if cfg!(target_family = "windows") {
r"\\?\C:\src\wibble.gleam"
} else {
"/src/wibble.gleam"
}))
.unwrap(),
range: Range {
start: Position {
line: 0,
character: 0
},
end: Position {
line: 0,
character: 15
}
}
})
)
}

#[test]
fn goto_definition_import_unqualified_type() {
let code = "
Expand Down
6 changes: 4 additions & 2 deletions compiler-core/src/type_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,9 @@ impl ValueConstructor {
}
| ValueConstructorVariant::ModuleConstant {
location, module, ..
}
| ValueConstructorVariant::ModuleFn {
location, module, ..
} => DefinitionLocation {
module: Some(module.as_str()),
span: *location,
Expand All @@ -973,8 +976,7 @@ impl ValueConstructor {
span: literal.location(),
},

ValueConstructorVariant::ModuleFn { location, .. }
| ValueConstructorVariant::LocalVariable { location } => DefinitionLocation {
ValueConstructorVariant::LocalVariable { location } => DefinitionLocation {
module: None,
span: *location,
},
Expand Down

0 comments on commit 8743158

Please sign in to comment.