Skip to content

Commit 6fccaf0

Browse files
authored
Merge branch 'master' into feat/forc-edit-subcommands-impl
2 parents 1f4a2ab + a70254b commit 6fccaf0

File tree

3 files changed

+41
-6
lines changed

3 files changed

+41
-6
lines changed

sway-lsp/src/capabilities/semantic_tokens.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,13 @@ pub fn semantic_tokens(tokens_sorted: &[&RefMulti<TokenIdent, Token>]) -> Semant
4747
for entry in tokens_sorted {
4848
let (ident, token) = entry.pair();
4949
let ty = semantic_token_type(&token.kind);
50-
let token_index = type_index(&ty);
51-
// TODO - improve with modifiers
52-
let modifier_bitset = 0;
53-
builder.push(ident.range, token_index, modifier_bitset);
50+
if let Some(token_index) = type_index(&ty) {
51+
// TODO - improve with modifiers
52+
let modifier_bitset = 0;
53+
builder.push(ident.range, token_index, modifier_bitset);
54+
} else {
55+
tracing::error!("Unsupported token type: {:?} for token: {:#?}", ty, token);
56+
}
5457
}
5558
builder.build()
5659
}
@@ -151,6 +154,7 @@ pub(crate) const SUPPORTED_TYPES: &[SemanticTokenType] = &[
151154
SemanticTokenType::new("selfKeyword"),
152155
SemanticTokenType::new("selfTypeKeyword"),
153156
SemanticTokenType::new("typeAlias"),
157+
SemanticTokenType::new("traitType"),
154158
];
155159

156160
pub(crate) const SUPPORTED_MODIFIERS: &[SemanticTokenModifier] = &[
@@ -194,6 +198,9 @@ fn semantic_token_type(kind: &SymbolKind) -> SemanticTokenType {
194198
}
195199
}
196200

197-
fn type_index(ty: &SemanticTokenType) -> u32 {
198-
SUPPORTED_TYPES.iter().position(|it| it == ty).unwrap() as u32
201+
fn type_index(ty: &SemanticTokenType) -> Option<u32> {
202+
SUPPORTED_TYPES
203+
.iter()
204+
.position(|it| it == ty)
205+
.map(|x| x as u32)
199206
}

sway-lsp/tests/lib.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,30 @@ fn did_open() {
156156
});
157157
}
158158

159+
#[test]
160+
fn did_open_all_std_lib_files() {
161+
run_async!({
162+
let (mut service, _) = LspService::new(ServerState::new);
163+
let files = sway_utils::helpers::get_sway_files(std_lib_dir().join("src"));
164+
for file in files {
165+
eprintln!("opening file: {:?}", file.as_path());
166+
167+
// If the workspace is not initialized, we need to initialize it
168+
// Otherwise, we can just open the file
169+
let uri = if service.inner().sync_workspace.get().is_none() {
170+
init_and_open(&mut service, file.to_path_buf()).await
171+
} else {
172+
open(service.inner(), file.to_path_buf()).await
173+
};
174+
175+
// Make sure that semantic tokens are successfully returned for the file
176+
let semantic_tokens = lsp::get_semantic_tokens_full(service.inner(), &uri).await;
177+
assert!(!semantic_tokens.data.is_empty());
178+
}
179+
shutdown_and_exit(&mut service).await;
180+
});
181+
}
182+
159183
// Opens all members in the examples workspace and assert that we are able to return semantic tokens for each workspace member.
160184
// This test is expected to run for a while although should be much faster once https://github.com/FuelLabs/sway/pull/7139 is merged.
161185
#[test]

sway-lsp/tests/utils/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ pub fn e2e_test_dir() -> PathBuf {
5858
.join("struct_field_access")
5959
}
6060

61+
pub fn std_lib_dir() -> PathBuf {
62+
sway_workspace_dir().join("sway-lib-std")
63+
}
64+
6165
pub fn runnables_test_dir() -> PathBuf {
6266
test_fixtures_dir().join("runnables")
6367
}

0 commit comments

Comments
 (0)