Skip to content

Commit 242397c

Browse files
Better project detection by language server (#633)
1 parent 75c7980 commit 242397c

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed

src/LanguageServer.spec.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,31 @@ describe('LanguageServer', () => {
440440
s`${tempDir}/root/subdir`
441441
]);
442442
});
443+
444+
it('finds nested roku-like dirs', async () => {
445+
fsExtra.outputFileSync(s`${tempDir}/project1/manifest`, '');
446+
fsExtra.outputFileSync(s`${tempDir}/project1/source/main.brs`, '');
447+
448+
fsExtra.outputFileSync(s`${tempDir}/sub/dir/project2/manifest`, '');
449+
fsExtra.outputFileSync(s`${tempDir}/sub/dir/project2/source/main.bs`, '');
450+
451+
//does not match folder with manifest without a sibling ./source folder
452+
fsExtra.outputFileSync(s`${tempDir}/project3/manifest`, '');
453+
454+
workspaceFolders = [
455+
s`${tempDir}/`
456+
];
457+
458+
server.run();
459+
await server['syncProjects']();
460+
461+
expect(
462+
server.projects.map(x => x.projectPath).sort()
463+
).to.eql([
464+
s`${tempDir}/project1`,
465+
s`${tempDir}/sub/dir/project2`
466+
]);
467+
});
443468
});
444469

445470
describe('onDidChangeWatchedFiles', () => {

src/LanguageServer.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,34 @@ export class LanguageServer {
270270
//if we found at least one bsconfig.json, then ALL projects must have a bsconfig.json.
271271
if (files.length > 0) {
272272
return files.map(file => s`${path.dirname(file.src)}`);
273-
} else {
274-
//treat the workspace folder as a brightscript project itself
275-
return [workspaceFolder];
276273
}
274+
275+
//look for roku project folders
276+
const rokuLikeDirs = (await Promise.all(
277+
//find all folders containing a `manifest` file
278+
(await rokuDeploy.getFilePaths([
279+
'**/manifest',
280+
...excludes
281+
282+
//is there at least one .bs|.brs file under the `/source` folder?
283+
], workspaceFolder)).map(async manifestEntry => {
284+
const manifestDir = path.dirname(manifestEntry.src);
285+
const files = await rokuDeploy.getFilePaths([
286+
'source/**/*.{brs,bs}',
287+
...excludes
288+
], manifestDir);
289+
if (files.length > 0) {
290+
return manifestDir;
291+
}
292+
})
293+
//throw out nulls
294+
)).filter(x => !!x);
295+
if (rokuLikeDirs.length > 0) {
296+
return rokuLikeDirs;
297+
}
298+
299+
//treat the workspace folder as a brightscript project itself
300+
return [workspaceFolder];
277301
}
278302

279303
/**

0 commit comments

Comments
 (0)