Skip to content
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
29 changes: 15 additions & 14 deletions src/LanguageServer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -969,17 +969,14 @@ describe('LanguageServer', () => {
});

it('should work for nested class as well', async () => {
const nestedNamespace = 'containerNamespace';
const nestedClassName = 'nestedClass';

addScriptFile('nested', `
namespace ${nestedNamespace}
class ${nestedClassName}
function pi()
namespace animals
class dog
function run()
return 3.141592653589793
end function

function buildAwesome()
function speak()
return 42
end function
end class
Expand All @@ -991,13 +988,17 @@ describe('LanguageServer', () => {
for (let i = 0; i < 2; i++) {
const symbols = await server['onWorkspaceSymbol']({} as any);
expect(symbols.length).to.equal(4);
expect(symbols[0].name).to.equal(`pi`);
expect(symbols[0].containerName).to.equal(`${nestedNamespace}.${nestedClassName}`);
expect(symbols[1].name).to.equal(`buildAwesome`);
expect(symbols[1].containerName).to.equal(`${nestedNamespace}.${nestedClassName}`);
expect(symbols[2].name).to.equal(`${nestedNamespace}.${nestedClassName}`);
expect(symbols[2].containerName).to.equal(nestedNamespace);
expect(symbols[3].name).to.equal(nestedNamespace);
expect(
symbols.map(x => ({
name: x.name,
containerName: x.containerName
})).sort((a, b) => a.name.localeCompare(b.name))
).to.eql([
{ name: 'animals', containerName: undefined },
{ name: `dog`, containerName: 'animals' },
{ name: `run`, containerName: 'dog' },
{ name: 'speak', containerName: 'dog' }
]);
}
});
});
Expand Down
22 changes: 13 additions & 9 deletions src/Program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Scope } from './Scope';
import { DiagnosticMessages } from './DiagnosticMessages';
import { BrsFile } from './files/BrsFile';
import { XmlFile } from './files/XmlFile';
import type { BsDiagnostic, File, FileReference, FileObj, BscFile, SemanticToken, AfterFileTranspileEvent, FileLink, ProvideHoverEvent, ProvideCompletionsEvent, Hover, ProvideDefinitionEvent, ProvideReferencesEvent, ProvideDocumentSymbolsEvent } from './interfaces';
import type { BsDiagnostic, File, FileReference, FileObj, BscFile, SemanticToken, AfterFileTranspileEvent, FileLink, ProvideHoverEvent, ProvideCompletionsEvent, Hover, ProvideDefinitionEvent, ProvideReferencesEvent, ProvideDocumentSymbolsEvent, ProvideWorkspaceSymbolsEvent } from './interfaces';
import { standardizePath as s, util } from './util';
import { XmlScope } from './XmlScope';
import { DiagnosticFilterer } from './DiagnosticFilterer';
Expand Down Expand Up @@ -905,14 +905,14 @@ export class Program {
* Goes through each file and builds a list of workspace symbols for the program. Used by LanguageServer's onWorkspaceSymbol functionality
*/
public getWorkspaceSymbols() {
const results = Object.keys(this.files).map(key => {
const file = this.files[key];
if (isBrsFile(file)) {
return file.getWorkspaceSymbols();
}
return [];
});
return util.flatMap(results, c => c);
const event: ProvideWorkspaceSymbolsEvent = {
program: this,
workspaceSymbols: []
};
this.plugins.emit('beforeProvideWorkspaceSymbols', event);
this.plugins.emit('provideWorkspaceSymbols', event);
this.plugins.emit('afterProvideWorkspaceSymbols', event);
return event.workspaceSymbols;
}

/**
Expand Down Expand Up @@ -961,6 +961,10 @@ export class Program {
return result ?? [];
}

/**
* Get full list of document symbols for a file
* @param srcPath path to the file
*/
public getDocumentSymbols(srcPath: string): DocumentSymbol[] | undefined {
let file = this.getFile(srcPath);
if (file) {
Expand Down
9 changes: 7 additions & 2 deletions src/bscPlugin/BscPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { isBrsFile, isXmlFile } from '../astUtils/reflection';
import type { BeforeFileTranspileEvent, CompilerPlugin, OnFileValidateEvent, OnGetCodeActionsEvent, ProvideHoverEvent, OnGetSemanticTokensEvent, OnScopeValidateEvent, ProvideCompletionsEvent, ProvideDefinitionEvent, ProvideReferencesEvent, ProvideDocumentSymbolsEvent } from '../interfaces';
import type { BeforeFileTranspileEvent, CompilerPlugin, OnFileValidateEvent, OnGetCodeActionsEvent, ProvideHoverEvent, OnGetSemanticTokensEvent, OnScopeValidateEvent, ProvideCompletionsEvent, ProvideDefinitionEvent, ProvideReferencesEvent, ProvideDocumentSymbolsEvent, ProvideWorkspaceSymbolsEvent } from '../interfaces';
import type { Program } from '../Program';
import { CodeActionsProcessor } from './codeActions/CodeActionsProcessor';
import { CompletionsProcessor } from './completions/CompletionsProcessor';
import { DefinitionProvider } from './definition/DefinitionProvider';
import { DocumentSymbolProcessor } from './documentSymbol/DocumentSymbolProcessor';
import { DocumentSymbolProcessor } from './symbols/DocumentSymbolProcessor';
import { HoverProcessor } from './hover/HoverProcessor';
import { ReferencesProvider } from './references/ReferencesProvider';
import { BrsFileSemanticTokensProcessor } from './semanticTokens/BrsFileSemanticTokensProcessor';
Expand All @@ -13,6 +13,7 @@ import { BrsFileValidator } from './validation/BrsFileValidator';
import { ProgramValidator } from './validation/ProgramValidator';
import { ScopeValidator } from './validation/ScopeValidator';
import { XmlFileValidator } from './validation/XmlFileValidator';
import { WorkspaceSymbolProcessor } from './symbols/WorkspaceSymbolProcessor';

export class BscPlugin implements CompilerPlugin {
public name = 'BscPlugin';
Expand All @@ -29,6 +30,10 @@ export class BscPlugin implements CompilerPlugin {
return new DocumentSymbolProcessor(event).process();
}

public provideWorkspaceSymbols(event: ProvideWorkspaceSymbolsEvent) {
return new WorkspaceSymbolProcessor(event).process();
}

public provideCompletions(event: ProvideCompletionsEvent) {
new CompletionsProcessor(event).process();
}
Expand Down
77 changes: 0 additions & 77 deletions src/bscPlugin/documentSymbol/DocumentSymbolProcessor.ts

This file was deleted.

28 changes: 28 additions & 0 deletions src/bscPlugin/symbols/DocumentSymbolProcessor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { isBrsFile } from '../../astUtils/reflection';
import type { BrsFile } from '../../files/BrsFile';
import type { ProvideDocumentSymbolsEvent } from '../../interfaces';
import { getDocumentSymbolsFromStatement } from './symbolUtils';

export class DocumentSymbolProcessor {
public constructor(
public event: ProvideDocumentSymbolsEvent
) {

}

public process() {
if (isBrsFile(this.event.file)) {
return this.getBrsFileDocumentSymbols(this.event.file);
}
}

private getBrsFileDocumentSymbols(file: BrsFile) {
for (const statement of file.ast.statements) {
const symbol = getDocumentSymbolsFromStatement(statement);
if (symbol) {
this.event.documentSymbols.push(...symbol);
}
}
return this.event.documentSymbols;
}
}
Loading