Skip to content

Commit

Permalink
Goto links for LSP hover (#4539)
Browse files Browse the repository at this point in the history
This is a subset of https://github.com/FuelLabs/sway/pull/4532/files.
I'm trying to narrow down why some of the e2e tests are failing. This PR
contains the changes for the "Go to type" links only, excluding the
changes in sway-core that were needed for "Goto implementations" to
work.

Closes #2852

<img width="673" alt="image"
src="https://user-images.githubusercontent.com/47993817/236371214-0b82b509-9a59-4575-b1d1-5acd505da255.png">

- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [ ] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [ ] I have added tests that prove my fix is effective or that my
feature works.
- [ ] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [ ] I have requested a review from the relevant team or maintainers.
  • Loading branch information
sdankel committed May 6, 2023
1 parent 34f1e98 commit d7996d8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
12 changes: 6 additions & 6 deletions sway-core/src/language/call_path.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{fmt, sync::Arc};

use crate::{Ident, Namespace};
use crate::{namespace::Module, Ident};

use sway_types::{span::Span, Spanned};

Expand Down Expand Up @@ -100,7 +100,7 @@ impl CallPath {
///
/// Paths to _external_ libraries such `std::lib1::lib2::my_obj` are considered full already
/// and are left unchanged since `std` is a root of the package `std`.
pub fn to_fullpath(&self, namespace: &mut Namespace) -> CallPath {
pub fn to_fullpath(&self, namespace: &Module) -> CallPath {
if self.is_absolute {
return self.clone();
}
Expand All @@ -123,11 +123,11 @@ impl CallPath {
let mut prefixes: Vec<Ident> = vec![];

if !is_external {
if let Some(pkg_name) = &namespace.root().module.name {
if let Some(pkg_name) = &namespace.name {
prefixes.push(pkg_name.clone());
}

for mod_path in namespace.mod_path() {
for mod_path in &namespace.mod_path {
prefixes.push(mod_path.clone());
}
}
Expand All @@ -149,10 +149,10 @@ impl CallPath {
self.clone()
} else {
let mut prefixes: Vec<Ident> = vec![];
if let Some(pkg_name) = &namespace.root().module.name {
if let Some(pkg_name) = &namespace.name {
prefixes.push(pkg_name.clone());
}
for mod_path in namespace.mod_path() {
for mod_path in &namespace.mod_path {
prefixes.push(mod_path.clone());
}

Expand Down
3 changes: 1 addition & 2 deletions sway-lsp/src/capabilities/hover/hover_link_contents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,10 @@ impl<'a> HoverLinkContents<'a> {
});
};
}

/// Adds all implementations of the given [TyTraitDecl] to the list of implementations.
pub fn add_implementations_for_trait(&mut self, trait_decl: &TyTraitDecl) {
if let Some(namespace) = self.session.namespace() {
let call_path = CallPath::from(trait_decl.name.clone()); //.to_fullpath(&namespace);
let call_path = CallPath::from(trait_decl.name.clone()).to_fullpath(&namespace);
let impl_spans = namespace.get_impl_spans_for_trait_name(&call_path);
self.add_implementations(&trait_decl.span(), impl_spans);
}
Expand Down

0 comments on commit d7996d8

Please sign in to comment.