Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix semantic tokens for components and interfaces, and m #1313

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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