Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
> - :house: [Internal]
> - :nail_care: [Polish]

## [Unreleased]

#### :bug: Bug fix

- Take namespace into account for incremental cleanup. https://github.com/rescript-lang/rescript-vscode/pull/1164

## 1.72.0

#### :bug: Bug fix
Expand Down
20 changes: 11 additions & 9 deletions server/src/incrementalCompilation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,19 +295,21 @@ function triggerIncrementalCompilationOfFile(
INCREMENTAL_FILE_FOLDER_LOCATION,
) as NormalizedPath;

// projectRootPath is already NormalizedPath, appending a constant string still makes it a NormalizedPath
let originalTypeFileLocation = path.resolve(
const relSourcePath = path.relative(projectRootPath, filePath);
const relSourceDir = path.dirname(relSourcePath);
const typeExt = ext === ".res" ? ".cmt" : ".cmti";
const originalTypeFileName =
project.namespaceName != null
? `${moduleName}-${project.namespaceName}${typeExt}`
: `${moduleName}${typeExt}`;
// projectRootPath is already NormalizedPath, appending constant strings still yields a NormalizedPath
const originalTypeFileLocation = path.resolve(
projectRootPath,
c.compilerDirPartialPath,
path.relative(projectRootPath, filePath),
relSourceDir,
originalTypeFileName,
) as NormalizedPath;

const parsed = path.parse(originalTypeFileLocation);
parsed.ext = ext === ".res" ? ".cmt" : ".cmti";
parsed.base = "";
// As originalTypeFileLocation was a NormalizedPath, path.format ensures we can assume string is now NormalizedPath
originalTypeFileLocation = path.format(parsed) as NormalizedPath;

incrementalFileCacheEntry = {
file: {
originalTypeFileLocation,
Expand Down
42 changes: 24 additions & 18 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import * as ic from "./incrementalCompilation";
import config, { extensionConfiguration, initialConfiguration } from "./config";
import { projectsFiles } from "./projectFiles";
import { NormalizedPath } from "./utils";
import { initializeLogger, getLogger, setLogLevel, LogLevel } from "./logger";
import { initializeLogger, getLogger, setLogLevel } from "./logger";

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

async function getServerVersion(): Promise<string | undefined> {
// Read the server version from package.json
let serverVersion: string | undefined;
try {
const packageJsonPath = path.join(__dirname, "..", "package.json");
const packageJsonContent = await fsAsync.readFile(packageJsonPath, {
encoding: "utf-8",
});
const packageJson: { version?: unknown } = JSON.parse(packageJsonContent);
serverVersion =
typeof packageJson.version === "string" ? packageJson.version : undefined;
} catch (e) {
// If we can't read the version, that's okay - we'll just omit it
serverVersion = undefined;
}
return serverVersion;
}

async function dumpServerState(
msg: p.RequestMessage,
): Promise<p.ResponseMessage> {
// Custom debug endpoint: dump current server state (config + projectsFiles)
try {
// Read the server version from package.json
let serverVersion: string | undefined;
try {
const packageJsonPath = path.join(__dirname, "..", "package.json");
const packageJsonContent = await fsAsync.readFile(packageJsonPath, {
encoding: "utf-8",
});
const packageJson: { version?: unknown } = JSON.parse(packageJsonContent);
serverVersion =
typeof packageJson.version === "string"
? packageJson.version
: undefined;
} catch (e) {
// If we can't read the version, that's okay - we'll just omit it
serverVersion = undefined;
}
const serverVersion = await getServerVersion();

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