Skip to content

Commit

Permalink
do not revalidate on changes that are outside of any workspace (#315)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgejecook committed Feb 15, 2021
1 parent 2aecd72 commit 6e0db6a
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 10 deletions.
39 changes: 39 additions & 0 deletions src/LanguageServer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ describe('LanguageServer', () => {
let libPath = s`${workspacePath}/source/lib.brs`;
writeToFs(libPath, 'sub lib(): return : end sub');

server.workspaces[0].configFilePath = `${workspacePath}/bsconfig.json`;
await svr.onDidChangeWatchedFiles({
changes: [{
uri: getFileProtocolPath(libPath),
Expand Down Expand Up @@ -351,6 +352,44 @@ describe('LanguageServer', () => {
pathAbsolute: s`${rootDir}/source/lib.brs`
}]);
});

it('does not trigger revalidates when changes are in files which are not tracked', async () => {
svr.connection = {
sendNotification: () => { }
};
svr.workspaces.push({
builder: {
getDiagnostics: () => [],
program: {
validate: () => { }
}
}
});

sinon.stub(util, 'isDirectorySync').returns(true);
sinon.stub(glob, 'sync').returns([
s`${rootDir}/source/main.brs`,
s`${rootDir}/source/lib.brs`
]);
const stub = sinon.stub(server, 'handleFileChanges').returns(Promise.resolve());

await (server as any).onDidChangeWatchedFiles({
changes: [{
type: FileChangeType.Created,
uri: getFileProtocolPath('some/other/folder/maybe/some/vscode/settings')
}]
} as DidChangeWatchedFilesParams);

expect(stub.callCount).to.equal(1);

expect(stub.getCalls()[0].args[1]).to.eql([{
type: FileChangeType.Created,
pathAbsolute: s`${rootDir}/source/main.brs`
}, {
type: FileChangeType.Created,
pathAbsolute: s`${rootDir}/source/lib.brs`
}]);
});
});

describe('onSignatureHelp', () => {
Expand Down
34 changes: 24 additions & 10 deletions src/LanguageServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -576,11 +576,13 @@ export class LanguageServer {
}
})
);
//wait for all of the programs to finish starting up
await this.waitAllProgramFirstRuns();
if (workspaces.length > 0) {
//wait for all of the programs to finish starting up
await this.waitAllProgramFirstRuns();

// valdiate all workspaces
this.validateAllThrottled(); //eslint-disable-line
// valdiate all workspaces
this.validateAllThrottled(); //eslint-disable-line
}
}

private getRootDir(workspace: Workspace) {
Expand Down Expand Up @@ -691,8 +693,11 @@ export class LanguageServer {
workspacesToReload.push(workspace);
}
}
//reload any workspaces that need to be reloaded
await this.reloadWorkspaces(workspacesToReload);
if (workspacesToReload.length > 0) {
//vsc can generate a ton of these changes, for vsc system files, so we need to bail if there's no work to do on any of our actual workspace files
//reload any workspaces that need to be reloaded
await this.reloadWorkspaces(workspacesToReload);
}

//set the list of workspaces to non-reloaded workspaces
workspaces = workspaces.filter(x => !workspacesToReload.includes(x));
Expand Down Expand Up @@ -736,9 +741,6 @@ export class LanguageServer {
await Promise.all(
workspaces.map((workspace) => this.handleFileChanges(workspace, changes))
);

//validate all workspaces
await this.validateAllThrottled();
}
this.connection.sendNotification('build-status', 'success');
}
Expand All @@ -751,11 +753,16 @@ export class LanguageServer {
public async handleFileChanges(workspace: Workspace, changes: { type: FileChangeType; pathAbsolute: string }[]) {
//this loop assumes paths are both file paths and folder paths, which eliminates the need to detect.
//All functions below can handle being given a file path AND a folder path, and will only operate on the one they are looking for
let consumeCount = 0;
await Promise.all(changes.map(async (change) => {
await this.keyedThrottler.run(change.pathAbsolute, async () => {
await this.handleFileChange(workspace, change);
consumeCount += await this.handleFileChange(workspace, change) ? 1 : 0;
});
}));

if (consumeCount > 0) {
await this.validateAllThrottled();
}
}

/**
Expand All @@ -767,6 +774,7 @@ export class LanguageServer {
const program = workspace.builder.program;
const options = workspace.builder.options;
const rootDir = workspace.builder.rootDir;

//deleted
if (change.type === FileChangeType.Deleted) {
//try to act on this path as a directory
Expand All @@ -775,6 +783,9 @@ export class LanguageServer {
//if this is a file loaded in the program, remove it
if (program.hasFile(change.pathAbsolute)) {
program.removeFile(change.pathAbsolute);
return true;
} else {
return false;
}

//created
Expand All @@ -793,8 +804,10 @@ export class LanguageServer {
},
await workspace.builder.getFileContents(change.pathAbsolute)
);
return true;
} else {
//no dest path means the program doesn't want this file
return false;
}

//changed
Expand All @@ -812,6 +825,7 @@ export class LanguageServer {
} else {
program.removeFile(change.pathAbsolute);
}
return true;
}
}

Expand Down

0 comments on commit 6e0db6a

Please sign in to comment.