Skip to content

Commit 332a087

Browse files
IwanBlueHotDog
Iwan
authored andcommitted
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 44911a3 commit 332a087

File tree

2 files changed

+32
-14
lines changed

2 files changed

+32
-14
lines changed

server/src/server.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -122,33 +122,33 @@ let openedFile = (fileUri: string, fileContent: string) => {
122122

123123
stupidFileContentCache.set(filePath, fileContent);
124124

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

180180
stupidFileContentCache.delete(filePath);
181181

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

server/src/utils.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,24 @@ export let findProjectRootOfFile = (
3434
}
3535
};
3636

37+
// the "build root" represents the nearest directory containing a "bsconfig.json" file.
38+
// "bsconfig.json" can be used to locate the nearest build artefacts
39+
export let findBuildRootOfFile = (
40+
source: p.DocumentUri
41+
): null | p.DocumentUri => {
42+
let dir = path.dirname(source);
43+
if (fs.existsSync(path.join(dir, c.bsconfigPartialPath))) {
44+
return dir;
45+
} else {
46+
if (dir === source) {
47+
// reached top
48+
return null;
49+
} else {
50+
return findBuildRootOfFile(dir);
51+
}
52+
}
53+
};
54+
3755
type execResult =
3856
| {
3957
kind: "success";

0 commit comments

Comments
 (0)