Skip to content

Commit d535be5

Browse files
author
Iwan
committed
Split project from from build root.
the "build root" represents the nearest directory containing a "bsconfig.json" file. "bsconfig.json" can be used to locate the nearest build artefacts and .compiler.log for diagnostics.
1 parent ed4a063 commit d535be5

File tree

2 files changed

+32
-14
lines changed

2 files changed

+32
-14
lines changed

server/src/server.ts

+14-14
Original file line numberDiff line numberDiff line change
@@ -121,33 +121,33 @@ let openedFile = (fileUri: string, fileContent: string) => {
121121

122122
stupidFileContentCache.set(filePath, fileContent);
123123

124-
let projectRootPath = utils.findProjectRootOfFile(filePath);
125-
if (projectRootPath != null) {
126-
if (!projectsFiles.has(projectRootPath)) {
127-
projectsFiles.set(projectRootPath, {
124+
let buildRootPath = utils.findBuildRootOfFile(filePath);
125+
if (buildRootPath != null) {
126+
if (!projectsFiles.has(buildRootPath)) {
127+
projectsFiles.set(buildRootPath, {
128128
openFiles: new Set(),
129129
filesWithDiagnostics: new Set(),
130130
bsbWatcherByEditor: null,
131131
});
132132
compilerLogsWatcher.add(
133-
path.join(projectRootPath, c.compilerLogPartialPath)
133+
path.join(buildRootPath, c.compilerLogPartialPath)
134134
);
135135
}
136-
let root = projectsFiles.get(projectRootPath)!;
136+
let root = projectsFiles.get(buildRootPath)!;
137137
root.openFiles.add(filePath);
138138
let firstOpenFileOfProject = root.openFiles.size === 1;
139139
// check if .bsb.lock is still there. If not, start a bsb -w ourselves
140140
// because otherwise the diagnostics info we'll display might be stale
141-
let bsbLockPath = path.join(projectRootPath, c.bsbLock);
141+
let bsbLockPath = path.join(buildRootPath, c.bsbLock);
142142
if (firstOpenFileOfProject && !fs.existsSync(bsbLockPath)) {
143-
let bsbPath = path.join(projectRootPath, c.bsbPartialPath);
143+
let bsbPath = path.join(buildRootPath, c.bsbPartialPath);
144144
// TODO: sometime stale .bsb.lock dangling. bsb -w knows .bsb.lock is
145145
// stale. Use that logic
146146
// TODO: close watcher when lang-server shuts down
147147
if (fs.existsSync(bsbPath)) {
148148
let payload: clientSentBuildAction = {
149149
title: c.startBuildAction,
150-
projectRootPath: projectRootPath,
150+
projectRootPath: buildRootPath,
151151
};
152152
let params = {
153153
type: p.MessageType.Info,
@@ -178,17 +178,17 @@ let closedFile = (fileUri: string) => {
178178

179179
stupidFileContentCache.delete(filePath);
180180

181-
let projectRootPath = utils.findProjectRootOfFile(filePath);
182-
if (projectRootPath != null) {
183-
let root = projectsFiles.get(projectRootPath);
181+
let buildRootPath = utils.findBuildRootOfFile(filePath);
182+
if (buildRootPath != null) {
183+
let root = projectsFiles.get(buildRootPath);
184184
if (root != null) {
185185
root.openFiles.delete(filePath);
186186
// clear diagnostics too if no open files open in said project
187187
if (root.openFiles.size === 0) {
188188
compilerLogsWatcher.unwatch(
189-
path.join(projectRootPath, c.compilerLogPartialPath)
189+
path.join(buildRootPath, c.compilerLogPartialPath)
190190
);
191-
deleteProjectDiagnostics(projectRootPath);
191+
deleteProjectDiagnostics(buildRootPath);
192192
if (root.bsbWatcherByEditor !== null) {
193193
root.bsbWatcherByEditor.kill();
194194
root.bsbWatcherByEditor = null;

server/src/utils.ts

+18
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,24 @@ export let findProjectRootOfFile = (
2525
}
2626
};
2727

28+
// the "build root" represents the nearest directory containing a "bsconfig.json" file.
29+
// "bsconfig.json" can be used to locate the nearest build artefacts
30+
export let findBuildRootOfFile = (
31+
source: p.DocumentUri
32+
): null | p.DocumentUri => {
33+
let dir = path.dirname(source);
34+
if (fs.existsSync(path.join(dir, c.bsconfigPartialPath))) {
35+
return dir;
36+
} else {
37+
if (dir === source) {
38+
// reached top
39+
return null;
40+
} else {
41+
return findBuildRootOfFile(dir);
42+
}
43+
}
44+
};
45+
2846
type execResult =
2947
| {
3048
kind: "success";

0 commit comments

Comments
 (0)