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
36 changes: 31 additions & 5 deletions src/LanguageServer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from './chai-config.spec';
import * as fsExtra from 'fs-extra';
import * as path from 'path';
import type { DidChangeWatchedFilesParams, Location, PublishDiagnosticsParams, WorkspaceFolder } from 'vscode-languageserver';
import type { ConfigurationItem, DidChangeWatchedFilesParams, Location, PublishDiagnosticsParams, WorkspaceFolder } from 'vscode-languageserver';
import { FileChangeType } from 'vscode-languageserver';
import { Deferred } from './deferred';
import { CustomCommands, LanguageServer } from './LanguageServer';
Expand Down Expand Up @@ -402,15 +402,41 @@ describe('LanguageServer', () => {
});

it('ignores bsconfig.json files from vscode ignored paths', async () => {
const mapItem = (item: ConfigurationItem) => {
if (item.section === 'files') {
return {
exclude: {
'**/vendor': true
}
};
} else if (item.section === 'search') {
return {
exclude: {
'**/temp': true
}
};
} else {
return {};
}
};

server.run();
sinon.stub(server['connection'].workspace, 'getConfiguration').returns(Promise.resolve({
exclude: {
'**/vendor': true
sinon.stub(server['connection'].workspace, 'getConfiguration').callsFake(
// @ts-expect-error Sinon incorrectly infers the type of this function
(items: any) => {
if (typeof items === 'string') {
return Promise.resolve({});
}
if (Array.isArray(items)) {
return Promise.resolve(items.map(mapItem));
}
return Promise.resolve(mapItem(items));
}
}) as any);
);
await server.onInitialized();

fsExtra.outputJsonSync(s`${workspacePath}/vendor/someProject/bsconfig.json`, {});
fsExtra.outputJsonSync(s`${workspacePath}/temp/someProject/bsconfig.json`, {});
//it always ignores node_modules
fsExtra.outputJsonSync(s`${workspacePath}/node_modules/someProject/bsconfig.json`, {});
await server['syncProjects']();
Expand Down
21 changes: 16 additions & 5 deletions src/LanguageServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -653,10 +653,22 @@ export class LanguageServer {
* Ask the client for the list of `files.exclude` patterns. Useful when determining if we should process a file
*/
private async getWorkspaceExcludeGlobs(workspaceFolder: string): Promise<string[]> {
const config = await this.getClientConfiguration<{ exclude: string[] }>(workspaceFolder, 'files');
const result = Object
.keys(config?.exclude ?? {})
.filter(x => config?.exclude?.[x])
const filesConfig = await this.getClientConfiguration<{ exclude: string[] }>(workspaceFolder, 'files');
const fileExcludes = this.extractExcludes(filesConfig);

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

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

private extractExcludes(config: { exclude: string[] }): string[] {
if (!config?.exclude) {
return [];
}
return Object
.keys(config.exclude)
.filter(x => config.exclude[x])
//vscode files.exclude patterns support ignoring folders without needing to add `**/*`. So for our purposes, we need to
//append **/* to everything without a file extension or magic at the end
.map(pattern => [
Expand All @@ -666,7 +678,6 @@ export class LanguageServer {
`${pattern}/**/*`
])
.flat(1);
return result;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/lsp/ProjectManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ describe('ProjectManager', () => {
fsExtra.outputFileSync(`${rootDir}/subdir/bsconfig.json`, '');
await manager.syncProjects([{
workspaceFolder: rootDir,
excludePatterns: ['subdir/**/*']
excludePatterns: ['**/subdir/**/*']
}]);
expect(
manager.projects.map(x => x.projectPath)
Expand Down
16 changes: 9 additions & 7 deletions src/lsp/ProjectManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -648,18 +648,20 @@ export class ProjectManager {
private async getProjectPaths(workspaceConfig: WorkspaceConfig) {
//get the list of exclude patterns, and negate them (so they actually work like excludes)
const excludePatterns = (workspaceConfig.excludePatterns ?? []).map(x => s`!${x}`);
let files = await rokuDeploy.getFilePaths([
'**/bsconfig.json',
//exclude all files found in `files.exclude`
...excludePatterns
], workspaceConfig.workspaceFolder);

let files = await fastGlob(['**/bsconfig.json', ...excludePatterns], {
cwd: workspaceConfig.workspaceFolder,
followSymbolicLinks: false,
absolute: true,
onlyFiles: true
});

//filter the files to only include those that are allowed by the path filterer
files = this.pathFilterer.filter(files, x => x.src);
files = this.pathFilterer.filter(files);

//if we found at least one bsconfig.json, then ALL projects must have a bsconfig.json.
if (files.length > 0) {
return files.map(file => s`${path.dirname(file.src)}`);
return files.map(file => s`${path.dirname(file)}`);
}

//look for roku project folders
Expand Down
Loading