Skip to content

Commit

Permalink
Pass through deprecated flag
Browse files Browse the repository at this point in the history
  • Loading branch information
TwitchBronBron committed Jun 4, 2024
1 parent 4b0aa7a commit 5752b8e
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 5 deletions.
8 changes: 8 additions & 0 deletions src/SemanticTokenUtils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ describe('SemanticTokenUtils', () => {
SemanticTokenModifiers.documentation //idx=8
])).to.eql(0b100001001);
});

it('properly handles deprecated and another', () => {
expect(getModifierBitFlags([
SemanticTokenModifiers.declaration, //idx=0
SemanticTokenModifiers.static, //idx=3
SemanticTokenModifiers.documentation //idx=8
])).to.eql(0b100001001);
});
});
});

Expand Down
7 changes: 7 additions & 0 deletions src/SemanticTokenUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,10 @@ export function getModifierBitFlags(modifiers: SemanticTokenModifiers[]) {
}
return result;
}

/**
* @deprecated
*/
function test(){}

Check failure on line 101 in src/SemanticTokenUtils.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

Missing space before opening brace

test();
3 changes: 2 additions & 1 deletion src/SymbolTypeFlag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ export const enum SymbolTypeFlag {
optional = 4,
private = 8,
protected = 16,
postTranspile = 32
postTranspile = 32,
deprecated = 64
}
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,20 @@ describe('BrsFileSemanticTokensProcessor', () => {
]);
});

it.only('marks setPort as deprecated', () => {

Check failure on line 492 in src/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

it.only not permitted
const file = program.setFile<BrsFile>('source/main.bs', `
sub main()
url = createObject("roUrlTransfer") as roUrlTransfer
url.setPort(80)
end sub
`);
program.validate();
expectSemanticTokensIncludes(file, [
// url.|setPort|(80)
[SemanticTokenTypes.method, 3, 20, 3, 27, [SemanticTokenModifiers.deprecated]]
]);
});

it('works for `new` statement', () => {
const file = program.setFile<BrsFile>('source/main.bs', `
class Person
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ export class BrsFileSemanticTokensProcessor {
if (symbolType?.isResolvable()) {
let info = this.getSemanticTokenInfo(node, symbolType, extraData);
if (info) {
//mark as deprecated if applicable
if ((extraData.flags & SymbolTypeFlag.deprecated)) { // eslint-disable-line no-bitwise
info.modifiers ??= [];
info.modifiers.push(SemanticTokenModifiers.deprecated);
}
this.addToken(token, info.type, info.modifiers);
}
}
Expand Down
30 changes: 26 additions & 4 deletions src/types/BuiltInInterfaceAdder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,16 @@ export class BuiltInInterfaceAdder {
const interfacesToLoop = builtInComponent.interfaces ?? [builtInComponent];

//add any direct methods from this component to the member table
for (const method of builtInComponent.methods ?? []) {
const methodFuncType = this.buildMethodFromDocData(method, overrides, thisType);
builtInMemberTable.addSymbol(method.name, { description: method.description, completionPriority: 1 }, methodFuncType, SymbolTypeFlag.runtime);
if (this.isBrightScriptComponent(thisType)) {
for (const method of builtInComponent.methods ?? []) {
const methodFuncType = this.buildMethodFromDocData(method, overrides, thisType);
let flags = SymbolTypeFlag.runtime;
//set the deprecated flag if applicable
if ((method as any).isDeprecated) {
flags |= SymbolTypeFlag.deprecated; // eslint-disable-line no-bitwise
}
builtInMemberTable.addSymbol(method.name, { description: method.description, completionPriority: 1 }, methodFuncType, flags);
}
}

for (const iface of interfacesToLoop) {
Expand Down Expand Up @@ -153,6 +160,16 @@ export class BuiltInInterfaceAdder {
}
}

static isBrightScriptComponent(theType: BscType) {
const componentName = this.getMatchingRokuComponentName(theType);
if (!componentName) {
// No component matches the given type
return;
}
const lowerComponentName = componentName.toLowerCase();
return !!components[lowerComponentName];
}

//the return type is a union of the three data types. Just pick the first item from each collection, as every item in the collection should have the same shape
static getMatchingRokuComponent(theType: BscType): typeof components['roappinfo'] & typeof interfaces['ifappinfo'] & typeof events['rourlevent'] {
const componentName = this.getMatchingRokuComponentName(theType);
Expand Down Expand Up @@ -184,7 +201,12 @@ export class BuiltInInterfaceAdder {
}
for (const method of builtInNode.methods ?? []) {
const methodFuncType = this.buildMethodFromDocData(method, null, thisType);
memberTable.addSymbol(method.name, { description: method.description, completionPriority: 1 }, methodFuncType, SymbolTypeFlag.runtime);
let flags = SymbolTypeFlag.runtime;
//set the deprecated flag if applicable
if (method.isDeprecated) {
flags |= SymbolTypeFlag.deprecated; // eslint-disable-line no-bitwise
}
memberTable.addSymbol(method.name, { description: method.description, completionPriority: 1 }, methodFuncType, flags);
}
}

Expand Down

0 comments on commit 5752b8e

Please sign in to comment.