Skip to content

Commit d216af4

Browse files
authored
Merge pull request #1164 from nojaf/fix-namespace-incremental-cleanup
Take namespace into account for incremental cleanup
2 parents 62ebd39 + 750a28b commit d216af4

File tree

3 files changed

+41
-27
lines changed

3 files changed

+41
-27
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
> - :house: [Internal]
1111
> - :nail_care: [Polish]
1212
13+
## [Unreleased]
14+
15+
#### :bug: Bug fix
16+
17+
- Take namespace into account for incremental cleanup. https://github.com/rescript-lang/rescript-vscode/pull/1164
18+
1319
## 1.72.0
1420

1521
#### :bug: Bug fix

server/src/incrementalCompilation.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -295,19 +295,21 @@ function triggerIncrementalCompilationOfFile(
295295
INCREMENTAL_FILE_FOLDER_LOCATION,
296296
) as NormalizedPath;
297297

298-
// projectRootPath is already NormalizedPath, appending a constant string still makes it a NormalizedPath
299-
let originalTypeFileLocation = path.resolve(
298+
const relSourcePath = path.relative(projectRootPath, filePath);
299+
const relSourceDir = path.dirname(relSourcePath);
300+
const typeExt = ext === ".res" ? ".cmt" : ".cmti";
301+
const originalTypeFileName =
302+
project.namespaceName != null
303+
? `${moduleName}-${project.namespaceName}${typeExt}`
304+
: `${moduleName}${typeExt}`;
305+
// projectRootPath is already NormalizedPath, appending constant strings still yields a NormalizedPath
306+
const originalTypeFileLocation = path.resolve(
300307
projectRootPath,
301308
c.compilerDirPartialPath,
302-
path.relative(projectRootPath, filePath),
309+
relSourceDir,
310+
originalTypeFileName,
303311
) as NormalizedPath;
304312

305-
const parsed = path.parse(originalTypeFileLocation);
306-
parsed.ext = ext === ".res" ? ".cmt" : ".cmti";
307-
parsed.base = "";
308-
// As originalTypeFileLocation was a NormalizedPath, path.format ensures we can assume string is now NormalizedPath
309-
originalTypeFileLocation = path.format(parsed) as NormalizedPath;
310-
311313
incrementalFileCacheEntry = {
312314
file: {
313315
originalTypeFileLocation,

server/src/server.ts

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import * as ic from "./incrementalCompilation";
2929
import config, { extensionConfiguration, initialConfiguration } from "./config";
3030
import { projectsFiles } from "./projectFiles";
3131
import { NormalizedPath } from "./utils";
32-
import { initializeLogger, getLogger, setLogLevel, LogLevel } from "./logger";
32+
import { initializeLogger, getLogger, setLogLevel } from "./logger";
3333

3434
function applyUserConfiguration(configuration: extensionConfiguration) {
3535
// We always want to spread the initial configuration to ensure all defaults are respected.
@@ -1285,27 +1285,30 @@ function openCompiledFile(msg: p.RequestMessage): p.Message {
12851285
return response;
12861286
}
12871287

1288+
async function getServerVersion(): Promise<string | undefined> {
1289+
// Read the server version from package.json
1290+
let serverVersion: string | undefined;
1291+
try {
1292+
const packageJsonPath = path.join(__dirname, "..", "package.json");
1293+
const packageJsonContent = await fsAsync.readFile(packageJsonPath, {
1294+
encoding: "utf-8",
1295+
});
1296+
const packageJson: { version?: unknown } = JSON.parse(packageJsonContent);
1297+
serverVersion =
1298+
typeof packageJson.version === "string" ? packageJson.version : undefined;
1299+
} catch (e) {
1300+
// If we can't read the version, that's okay - we'll just omit it
1301+
serverVersion = undefined;
1302+
}
1303+
return serverVersion;
1304+
}
1305+
12881306
async function dumpServerState(
12891307
msg: p.RequestMessage,
12901308
): Promise<p.ResponseMessage> {
12911309
// Custom debug endpoint: dump current server state (config + projectsFiles)
12921310
try {
1293-
// Read the server version from package.json
1294-
let serverVersion: string | undefined;
1295-
try {
1296-
const packageJsonPath = path.join(__dirname, "..", "package.json");
1297-
const packageJsonContent = await fsAsync.readFile(packageJsonPath, {
1298-
encoding: "utf-8",
1299-
});
1300-
const packageJson: { version?: unknown } = JSON.parse(packageJsonContent);
1301-
serverVersion =
1302-
typeof packageJson.version === "string"
1303-
? packageJson.version
1304-
: undefined;
1305-
} catch (e) {
1306-
// If we can't read the version, that's okay - we'll just omit it
1307-
serverVersion = undefined;
1308-
}
1311+
const serverVersion = await getServerVersion();
13091312

13101313
const projects = Array.from(projectsFiles.entries()).map(
13111314
([projectRootPath, pf]) => ({
@@ -1477,7 +1480,10 @@ async function onMessage(msg: p.Message) {
14771480
};
14781481
send(response);
14791482
} else if (msg.method === "initialize") {
1480-
getLogger().info("Received initialize request from client.");
1483+
const serverVersion = await getServerVersion();
1484+
getLogger().info(
1485+
`Received initialize request from client. Server version: ${serverVersion}`,
1486+
);
14811487
// Save initial configuration, if present
14821488
let initParams = msg.params as InitializeParams;
14831489
for (const workspaceFolder of initParams.workspaceFolders || []) {

0 commit comments

Comments
 (0)