Skip to content

Commit 148a369

Browse files
committed
Minor cleanups
1 parent 6b1ed82 commit 148a369

2 files changed

Lines changed: 26 additions & 14 deletions

File tree

vhdl_ls/src/vhdl_server.rs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,10 @@ mod tests {
511511
use std::rc::Rc;
512512

513513
use super::*;
514-
use crate::rpc_channel::test_support::*;
514+
use crate::{
515+
rpc_channel::test_support::*,
516+
vhdl_server::semantic_tokens::{ENUM_MEMBER, FUNCTION, MOD_READONLY, PARAMETER, VARIABLE},
517+
};
515518

516519
pub(crate) fn initialize_server(server: &mut VHDLServer, root_uri: Url) {
517520
let capabilities = ClientCapabilities::default();
@@ -1088,7 +1091,7 @@ end package;
10881091
let decoded = get_semantic_tokens(&mut server, &uri);
10891092
assert_eq!(
10901093
token_at(&decoded, 1, " constant ".len() as u32),
1091-
Some((0, 1))
1094+
Some((VARIABLE, MOD_READONLY))
10921095
);
10931096
}
10941097

@@ -1135,20 +1138,26 @@ end architecture;
11351138
// signal and variable declarations: variable token, no modifiers
11361139
assert_eq!(
11371140
token_at(&decoded, 6, " signal ".len() as u32),
1138-
Some((0, 0))
1141+
Some((VARIABLE, 0))
11391142
);
11401143
assert_eq!(
11411144
token_at(&decoded, 9, " variable ".len() as u32),
1142-
Some((0, 0))
1145+
Some((VARIABLE, 0))
11431146
);
11441147
// constant usage: variable token + readonly modifier
11451148
assert_eq!(
11461149
token_at(&decoded, 11, " v1 := ".len() as u32),
1147-
Some((0, 1))
1150+
Some((VARIABLE, MOD_READONLY))
11481151
);
11491152
// signal and port usages
1150-
assert_eq!(token_at(&decoded, 12, " ".len() as u32), Some((0, 0)));
1151-
assert_eq!(token_at(&decoded, 14, " ".len() as u32), Some((0, 0)));
1153+
assert_eq!(
1154+
token_at(&decoded, 12, " ".len() as u32),
1155+
Some((VARIABLE, 0))
1156+
);
1157+
assert_eq!(
1158+
token_at(&decoded, 14, " ".len() as u32),
1159+
Some((VARIABLE, 0))
1160+
);
11521161
}
11531162

11541163
#[test]
@@ -1178,7 +1187,7 @@ end architecture;
11781187
// generic: variable + readonly
11791188
assert_eq!(
11801189
token_at(&decoded, 1, " generic (".len() as u32),
1181-
Some((0, 1))
1190+
Some((VARIABLE, MOD_READONLY))
11821191
);
11831192
// port: variable, no modifiers
11841193
assert_eq!(token_at(&decoded, 2, " port (".len() as u32), Some((0, 0)));
@@ -1216,17 +1225,17 @@ end package body;
12161225
assert_eq!(token_at(&decoded, 1, " type ".len() as u32), Some((9, 0))); // enum
12171226
assert_eq!(
12181227
token_at(&decoded, 1, " type my_enum is (".len() as u32),
1219-
Some((3, 0))
1228+
Some((ENUM_MEMBER, 0))
12201229
); // enum_member
12211230
assert_eq!(token_at(&decoded, 2, " type ".len() as u32), Some((8, 0))); // struct
12221231
assert_eq!(token_at(&decoded, 3, " ".len() as u32), Some((2, 0))); // property
12231232
assert_eq!(
12241233
token_at(&decoded, 5, " function ".len() as u32),
1225-
Some((4, 0))
1234+
Some((FUNCTION, 0))
12261235
); // function
12271236
assert_eq!(
12281237
token_at(&decoded, 5, " function add_one(".len() as u32),
1229-
Some((1, 0))
1238+
Some((PARAMETER, 0))
12301239
); // parameter
12311240
}
12321241
}

vhdl_ls/src/vhdl_server/semantic_tokens.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ macro_rules! define_token_types {
1818
(@consts $idx:expr, ) => {};
1919
// Recursive case: assign current index, increment for the rest
2020
(@consts $idx:expr, $const:ident, $( $rest:ident, )*) => {
21-
const $const: u32 = $idx;
21+
pub(crate) const $const: u32 = $idx;
2222
define_token_types!(@consts ($idx + 1), $( $rest, )*);
2323
};
2424
}
@@ -37,7 +37,7 @@ define_token_types! {
3737
}
3838

3939
// Semantic token modifier bits
40-
const MOD_READONLY: u32 = 1 << 0;
40+
pub(crate) const MOD_READONLY: u32 = 1 << 0;
4141

4242
pub const TOKEN_MODIFIERS: &[SemanticTokenModifier] = &[
4343
SemanticTokenModifier::READONLY, // bit 0: constants, generics
@@ -158,7 +158,10 @@ fn classify(kind: &AnyEntKind) -> Option<TokenClassification> {
158158
token_type: CLASS,
159159
modifiers: 0,
160160
},
161-
AnyEntKind::Concurrent(..) | AnyEntKind::Sequential(..) => return None,
161+
AnyEntKind::Concurrent(..) | AnyEntKind::Sequential(..) => TokenClassification {
162+
token_type: NAMESPACE,
163+
modifiers: 0,
164+
},
162165
};
163166
Some(result)
164167
}

0 commit comments

Comments
 (0)