|
@@ -9,6 +9,7 @@
|
|
|
|
|
|
|
|
import { M2Symbol, M2Unit, parseUnitText } from './parser';
|
|
import { M2Symbol, M2Unit, parseUnitText } from './parser';
|
|
|
import { flattenUnit, identifierOccurrences, resolveName } from './resolve';
|
|
import { flattenUnit, identifierOccurrences, resolveName } from './resolve';
|
|
|
|
|
+import { TYPE_BUILTINS } from './checker';
|
|
|
|
|
|
|
|
export const SEMANTIC_TOKEN_TYPES = [
|
|
export const SEMANTIC_TOKEN_TYPES = [
|
|
|
'namespace', // modules
|
|
'namespace', // modules
|
|
@@ -57,16 +58,29 @@ export function computeSemanticTokens(text: string, filePath: string, docDir: st
|
|
|
for (const occ of identifierOccurrences(text)) {
|
|
for (const occ of identifierOccurrences(text)) {
|
|
|
if (declared.has(`${occ.line}:${occ.ch}`)) continue;
|
|
if (declared.has(`${occ.line}:${occ.ch}`)) continue;
|
|
|
const resolved = resolveName(unit, docDir, occ.line, occ.ch, occ.qualifier, occ.name);
|
|
const resolved = resolveName(unit, docDir, occ.line, occ.ch, occ.qualifier, occ.name);
|
|
|
- if (!resolved) continue;
|
|
|
|
|
- const kind = useTokenKind(resolved.sym);
|
|
|
|
|
- if (kind === null) continue;
|
|
|
|
|
- out.push({
|
|
|
|
|
- line: occ.line,
|
|
|
|
|
- ch: occ.ch,
|
|
|
|
|
- length: Math.max(1, occ.endCh - occ.ch),
|
|
|
|
|
- type: kind,
|
|
|
|
|
- modifiers: 0,
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ if (resolved) {
|
|
|
|
|
+ const kind = useTokenKind(resolved.sym);
|
|
|
|
|
+ if (kind === null) continue;
|
|
|
|
|
+ out.push({
|
|
|
|
|
+ line: occ.line,
|
|
|
|
|
+ ch: occ.ch,
|
|
|
|
|
+ length: Math.max(1, occ.endCh - occ.ch),
|
|
|
|
|
+ type: kind,
|
|
|
|
|
+ modifiers: 0,
|
|
|
|
|
+ });
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ // Predeclared type names (`INTEGER`, …) resolve to no declaration.
|
|
|
|
|
+ // User shadowing still wins: anything declared resolves above.
|
|
|
|
|
+ if (TYPE_BUILTINS.has(occ.name)) {
|
|
|
|
|
+ out.push({
|
|
|
|
|
+ line: occ.line,
|
|
|
|
|
+ ch: occ.ch,
|
|
|
|
|
+ length: Math.max(1, occ.endCh - occ.ch),
|
|
|
|
|
+ type: typeIndex('type'),
|
|
|
|
|
+ modifiers: 0,
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
out.sort((a, b) => a.line - b.line || a.ch - b.ch);
|
|
out.sort((a, b) => a.line - b.line || a.ch - b.ch);
|
|
|
const data: number[] = [];
|
|
const data: number[] = [];
|