Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
44 changes: 44 additions & 0 deletions src/LanguageServer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -544,13 +544,57 @@ describe('LanguageServer', () => {
languageServer: {
enableThreading: false,
enableProjectDiscovery: true,
projectDiscoveryExclude: undefined,
logLevel: 'info'
}
}
]);
});
});

describe('projectDiscoveryExclude and files.watcherExclude', () => {
it('includes projectDiscoveryExclude in workspace configuration', async () => {
const projectDiscoveryExclude = ['**/test/**', 'node_modules/**'];

sinon.stub(server as any, 'getClientConfiguration').callsFake((workspaceFolder, section) => {
if (section === 'brightscript') {
return Promise.resolve({
languageServer: {
projectDiscoveryExclude: projectDiscoveryExclude
}
});
}
return Promise.resolve({});
});

server.run();
const configs = await server['getWorkspaceConfigs']();
expect(configs[0].languageServer.projectDiscoveryExclude).to.deep.equal(projectDiscoveryExclude);
});

it('includes files.watcherExclude in workspace exclude patterns', async () => {
const watcherExclude = {
'**/tmp/**': true,
'**/cache/**': true
};

sinon.stub(server as any, 'getClientConfiguration').callsFake((workspaceFolder, section) => {
if (section === 'files') {
return Promise.resolve({
exclude: { 'node_modules': true },
watcherExclude: watcherExclude
});
}
return Promise.resolve({});
});

server.run();
const excludeGlobs = await server['getWorkspaceExcludeGlobs'](workspaceFolders[0]);
expect(excludeGlobs).to.include('**/tmp/**');
expect(excludeGlobs).to.include('**/cache/**');
});
});

describe('onInitialize', () => {
it('sets capabilities', async () => {
server['hasConfigurationCapability'] = false;
Expand Down
16 changes: 13 additions & 3 deletions src/LanguageServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ export class LanguageServer {
languageServer: {
enableThreading: brightscriptConfig.languageServer?.enableThreading ?? LanguageServer.enableThreadingDefault,
enableProjectDiscovery: brightscriptConfig.languageServer?.enableProjectDiscovery ?? LanguageServer.enableProjectDiscoveryDefault,
projectDiscoveryExclude: brightscriptConfig.languageServer?.projectDiscoveryExclude,
logLevel: brightscriptConfig?.languageServer?.logLevel
}
};
Expand Down Expand Up @@ -647,6 +648,13 @@ export class LanguageServer {
this.pathFilterer.registerExcludeList(rootDir, workspaceConfig.excludePatterns)
);

//get any `projectDiscoveryExclude` patterns from the client from this workspace
if (workspaceConfig.languageServer?.projectDiscoveryExclude) {
this.pathFiltererDisposables.push(
this.pathFilterer.registerExcludeList(rootDir, workspaceConfig.languageServer.projectDiscoveryExclude)
);
}

//get any .gitignore patterns from the client from this workspace
const gitignorePath = path.resolve(rootDir, '.gitignore');
if (await fsExtra.pathExists(gitignorePath)) {
Expand All @@ -672,16 +680,17 @@ export class LanguageServer {
}

/**
* Ask the client for the list of `files.exclude` patterns. Useful when determining if we should process a file
* Ask the client for the list of `files.exclude` and `files.watcherExclude` patterns. Useful when determining if we should process a file
*/
private async getWorkspaceExcludeGlobs(workspaceFolder: string): Promise<string[]> {
const filesConfig = await this.getClientConfiguration<{ exclude: string[] }>(workspaceFolder, 'files');
const filesConfig = await this.getClientConfiguration<{ exclude: string[]; watcherExclude: string[] }>(workspaceFolder, 'files');
const fileExcludes = this.extractExcludes(filesConfig);
const watcherExcludes = this.extractExcludes({ exclude: filesConfig?.watcherExclude });

const searchConfig = await this.getClientConfiguration<{ exclude: string[] }>(workspaceFolder, 'search');
const searchExcludes = this.extractExcludes(searchConfig);

return [...fileExcludes, ...searchExcludes];
return [...fileExcludes, ...watcherExcludes, ...searchExcludes];
}

private extractExcludes(config: { exclude: string[] }): string[] {
Expand Down Expand Up @@ -824,6 +833,7 @@ export interface BrightScriptClientConfiguration {
languageServer: {
enableThreading: boolean;
enableProjectDiscovery: boolean;
projectDiscoveryExclude?: string[];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incorrect. It should follow the same structure as files.exclude and watch.exclude. An object with keys as string globs, and booleans as enabled/disabled. Please revert most of what you did in the last commit and adjust to this object structure. be sure to fix the documentation, these interfaces, and restore the old extractExcludes function to how it was.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted projectDiscoveryExclude to use object structure (Record<string, boolean>) instead of array format. Updated the interface definition, restored the original extractExcludes function, updated documentation examples, and ensured all tests pass. Changes committed in 2328860.

logLevel: LogLevel | string;
};
}
Expand Down
4 changes: 4 additions & 0 deletions src/lsp/ProjectManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,10 @@ export interface WorkspaceConfig {
* Should the language server automatically discover projects in this workspace?
*/
enableProjectDiscovery: boolean;
/**
* A list of glob patterns used to _exclude_ files from project discovery
*/
projectDiscoveryExclude?: string[];
/**
* The log level to use for this workspace
*/
Expand Down