Skip to content

Commit

Permalink
Fix semantic tokens for components and interfaces, and m (#1313)
Browse files Browse the repository at this point in the history
* Fix semantic tokens for component and interface instances.

* Fix lint issue and failing test
  • Loading branch information
TwitchBronBron authored Oct 1, 2024
1 parent 25fc065 commit abd960c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,6 @@ describe('BrsFileSemanticTokensProcessor', () => {
expectSemanticTokens(file, [
// sub |init|()
[SemanticTokenTypes.function, 1, 16, 1, 20],
// |m|.alien = new Humanoids.Aliens.Alien.NOT_A_CLASS() 'bs:disable-line
[SemanticTokenTypes.variable, 2, 16, 2, 17],
// m.alien = new |Humanoids|.Aliens.Alien.NOT_A_CLASS() 'bs:disable-line
[SemanticTokenTypes.namespace, 2, 30, 2, 39],
// m.alien = new Humanoids.|Aliens|.Alien.NOT_A_CLASS() 'bs:disable-line
Expand Down Expand Up @@ -503,6 +501,36 @@ describe('BrsFileSemanticTokensProcessor', () => {
], false);
});

it('does not color variable of type roSGNode as a type', () => {
const file = program.setFile<BrsFile>('source/main.bs', `
sub main()
node = CreateObject("roSGNode", "ContentNode")
node.id = "content"
end sub
`);
program.validate();
expectSemanticTokensIncludes(file, [
// |node|.id = "content"
[SemanticTokenTypes.variable, 3, 16, 3, 20]
], false);
});

it('does not color variable when it is an instance of an interface', () => {
const file = program.setFile<BrsFile>('source/main.bs', `
sub main(video as Movie)
video.url = "http://example.com"
end sub
interface Movie
url as string
end interface
`);
program.validate();
expectSemanticTokensIncludes(file, [
// |video|.url = "http://example.com"
[SemanticTokenTypes.variable, 2, 16, 2, 21]
], false);
});

it('works for `new` statement', () => {
const file = program.setFile<BrsFile>('source/main.bs', `
class Person
Expand Down
10 changes: 7 additions & 3 deletions src/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ export class BrsFileSemanticTokensProcessor {
} else {
return { type: SemanticTokenTypes.method };
}
} else if (isInterfaceType(type)) {
} else if (isInterfaceType(type) && extraData.isInstance !== true) {
return { type: SemanticTokenTypes.interface };
} else if (isComponentType(type)) {
} else if (isComponentType(type) && extraData.isInstance !== true) {
return { type: SemanticTokenTypes.class };
} else if (isEnumType(type)) {
return { type: SemanticTokenTypes.enum };
Expand All @@ -146,7 +146,11 @@ export class BrsFileSemanticTokensProcessor {
} else if (isConstStatement(node)) {
return { type: SemanticTokenTypes.variable, modifiers: [SemanticTokenModifiers.readonly, SemanticTokenModifiers.static] };
} else if (isVariableExpression(node)) {
return { type: SemanticTokenTypes.variable };
if (/m/i.test(node.tokens?.name?.text)) {
//don't color `m` variables
} else {
return { type: SemanticTokenTypes.variable };
}
} else {
//we don't know what it is...return undefined to prevent creating a semantic token
}
Expand Down

0 comments on commit abd960c

Please sign in to comment.