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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
#### :bug: Bug fix

- Fix rewatch lockfile detection on Windows. https://github.com/rescript-lang/rescript-vscode/pull/1160
- Override default `initialConfiguration` with user specific config. https://github.com/rescript-lang/rescript-vscode/pull/1162

#### :nail_care: Polish

- Resolve symlinks when finding platform binaries. https://github.com/rescript-lang/rescript-vscode/pull/1154
- Use `window/logMessage` in LSP Server for logging. https://github.com/rescript-lang/rescript-vscode/pull/1162

## 1.70.0

Expand Down
16 changes: 11 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,6 @@
"default": false,
"description": "(beta/experimental) Enable incremental type checking across files, so that unsaved file A gets access to unsaved file B."
},
"rescript.settings.incrementalTypechecking.debugLogging": {
"type": "boolean",
"default": false,
"description": "(debug) Enable debug logging (ends up in the extension output)."
},
"rescript.settings.cache.projectConfig.enable": {
"type": "boolean",
"default": true,
Expand Down Expand Up @@ -233,6 +228,17 @@
"type": "boolean",
"default": true,
"description": "Show compile status in the status bar (compiling/errors/warnings/success)."
},
"rescript.settings.logLevel": {
"type": "string",
"enum": [
"error",
"warn",
"info",
"log"
],
"default": "info",
"description": "Verbosity of ReScript language server logs sent to the Output channel."
}
}
},
Expand Down
18 changes: 6 additions & 12 deletions server/src/bsc-args/rewatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ import * as utils from "../utils";
import * as cp from "node:child_process";
import * as p from "vscode-languageserver-protocol";
import semver from "semver";
import {
debug,
IncrementallyCompiledFileInfo,
} from "../incrementalCompilation";
import { IncrementallyCompiledFileInfo } from "../incrementalCompilation";
import type { projectFiles } from "../projectFiles";
import { jsonrpcVersion } from "../constants";
import { getLogger } from "../logger";

export type RewatchCompilerArgs = {
compiler_args: Array<string>;
Expand Down Expand Up @@ -68,15 +66,11 @@ export async function getRewatchBscArgs(

if (rescriptRewatchPath != null) {
rewatchPath = rescriptRewatchPath;
if (debug()) {
console.log(
`Found rewatch binary bundled with v12: ${rescriptRewatchPath}`,
);
}
getLogger().log(
`Found rewatch binary bundled with v12: ${rescriptRewatchPath}`,
);
} else {
if (debug()) {
console.log("Did not find rewatch binary bundled with v12");
}
getLogger().log("Did not find rewatch binary bundled with v12");
}

const rewatchArguments = semver.satisfies(
Expand Down
52 changes: 27 additions & 25 deletions server/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export type send = (msg: Message) => void;

export interface extensionConfiguration {
askToStartBuild?: boolean;
logLevel?: "error" | "warn" | "info" | "log";
inlayHints?: {
enable?: boolean;
maxLength?: number | null;
Expand All @@ -19,7 +20,6 @@ export interface extensionConfiguration {
incrementalTypechecking?: {
enable?: boolean;
acrossFiles?: boolean;
debugLogging?: boolean;
};
cache?: {
projectConfig?: {
Expand All @@ -28,33 +28,35 @@ export interface extensionConfiguration {
};
}

// All values here are temporary, and will be overridden as the server is
// initialized, and the current config is received from the client.
let config: { extensionConfiguration: extensionConfiguration } = {
extensionConfiguration: {
askToStartBuild: true,
inlayHints: {
enable: false,
maxLength: 25,
},
codeLens: false,
binaryPath: null,
platformPath: null,
signatureHelp: {
enabled: true,
forConstructorPayloads: true,
},
incrementalTypechecking: {
export const initialConfiguration: extensionConfiguration = {
askToStartBuild: true,
logLevel: "info",
inlayHints: {
enable: false,
maxLength: 25,
},
codeLens: false,
binaryPath: null,
platformPath: null,
signatureHelp: {
enabled: true,
forConstructorPayloads: true,
},
incrementalTypechecking: {
enable: true,
acrossFiles: false,
},
cache: {
projectConfig: {
enable: true,
acrossFiles: false,
debugLogging: false,
},
cache: {
projectConfig: {
enable: true,
},
},
},
};

// All values here are temporary, and will be overridden as the server is
// initialized, and the current config is received from the client.
let config: { extensionConfiguration: extensionConfiguration } = {
extensionConfiguration: initialConfiguration,
};

export default config;
102 changes: 37 additions & 65 deletions server/src/incrementalCompilation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@ import { getRewatchBscArgs, RewatchCompilerArgs } from "./bsc-args/rewatch";
import { BsbCompilerArgs, getBsbBscArgs } from "./bsc-args/bsb";
import { getCurrentCompilerDiagnosticsForFile } from "./server";
import { NormalizedPath } from "./utils";

export function debug() {
return (
config.extensionConfiguration.incrementalTypechecking?.debugLogging ?? false
);
}
import { getLogger } from "./logger";

const INCREMENTAL_FOLDER_NAME = "___incremental";
const INCREMENTAL_FILE_FOLDER_LOCATION = path.join(
Expand Down Expand Up @@ -96,13 +91,11 @@ export function incrementalCompilationFileChanged(changedPath: NormalizedPath) {
if (filePath != null) {
const entry = incrementallyCompiledFileInfo.get(filePath);
if (entry != null) {
if (debug()) {
console.log("[watcher] Cleaning up incremental files for " + filePath);
}
getLogger().log(
"[watcher] Cleaning up incremental files for " + filePath,
);
if (entry.compilation != null) {
if (debug()) {
console.log("[watcher] Was compiling, killing");
}
getLogger().log("[watcher] Was compiling, killing");
clearTimeout(entry.compilation.timeout);
entry.killCompilationListeners.forEach((cb) => cb());
entry.compilation = null;
Expand All @@ -129,9 +122,7 @@ export function removeIncrementalFileFolder(
}

export function recreateIncrementalFileFolder(projectRootPath: NormalizedPath) {
if (debug()) {
console.log("Recreating incremental file folder");
}
getLogger().log("Recreating incremental file folder");
removeIncrementalFileFolder(projectRootPath, () => {
fs.mkdir(
path.resolve(projectRootPath, INCREMENTAL_FILE_FOLDER_LOCATION),
Expand All @@ -153,9 +144,7 @@ export function cleanUpIncrementalFiles(
? `${fileNameNoExt}-${namespace.result}`
: fileNameNoExt;

if (debug()) {
console.log("Cleaning up incremental file assets for: " + fileNameNoExt);
}
getLogger().log("Cleaning up incremental file assets for: " + fileNameNoExt);

fs.unlink(
path.resolve(
Expand Down Expand Up @@ -252,15 +241,14 @@ function triggerIncrementalCompilationOfFile(
// New file
const projectRootPath = utils.findProjectRootOfFile(filePath);
if (projectRootPath == null) {
if (debug())
console.log("Did not find project root path for " + filePath);
getLogger().log("Did not find project root path for " + filePath);
return;
}
// projectRootPath is already normalized (NormalizedPath) from findProjectRootOfFile
// Use getProjectFile to verify the project exists
const project = utils.getProjectFile(projectRootPath);
if (project == null) {
if (debug()) console.log("Did not find open project for " + filePath);
getLogger().log("Did not find open project for " + filePath);
return;
}

Expand All @@ -279,20 +267,19 @@ function triggerIncrementalCompilationOfFile(
projectRootPath != null &&
utils.findProjectRootOfDir(projectRootPath) != null;

if (foundRewatchLockfileInProjectRoot && debug()) {
console.log(
if (foundRewatchLockfileInProjectRoot) {
getLogger().log(
`Found rewatch/rescript lockfile in project root, treating as local package in workspace`,
);
} else if (!foundRewatchLockfileInProjectRoot && debug()) {
console.log(
} else {
getLogger().log(
`Did not find rewatch/rescript lockfile in project root, assuming bsb`,
);
}

const bscBinaryLocation = project.bscBinaryLocation;
if (bscBinaryLocation == null) {
if (debug())
console.log("Could not find bsc binary location for " + filePath);
getLogger().log("Could not find bsc binary location for " + filePath);
return;
}
const ext = filePath.endsWith(".resi") ? ".resi" : ".res";
Expand Down Expand Up @@ -401,12 +388,9 @@ async function figureOutBscArgs(
) {
const project = projectsFiles.get(entry.project.rootPath);
if (project?.rescriptVersion == null) {
if (debug()) {
console.log(
"Found no project (or ReScript version) for " +
entry.file.sourceFilePath,
);
}
getLogger().log(
"Found no project (or ReScript version) for " + entry.file.sourceFilePath,
);
return null;
}
const res = await getBscArgs(send, entry);
Expand Down Expand Up @@ -515,11 +499,9 @@ async function compileContents(
callArgs = callArgsRetried;
entry.project.callArgs = Promise.resolve(callArgsRetried);
} else {
if (debug()) {
console.log(
"Could not figure out call args. Maybe build.ninja does not exist yet?",
);
}
getLogger().log(
"Could not figure out call args. Maybe build.ninja does not exist yet?",
);
return;
}
}
Expand All @@ -537,41 +519,35 @@ async function compileContents(
entry.buildSystem === "bsb"
? entry.project.rootPath
: path.resolve(entry.project.rootPath, c.compilerDirPartialPath);
if (debug()) {
console.log(
`About to invoke bsc from \"${cwd}\", used ${entry.buildSystem}`,
);
console.log(
`${entry.project.bscBinaryLocation} ${callArgs.map((c) => `"${c}"`).join(" ")}`,
);
}
getLogger().log(
`About to invoke bsc from \"${cwd}\", used ${entry.buildSystem}`,
);
getLogger().log(
`${entry.project.bscBinaryLocation} ${callArgs.map((c) => `"${c}"`).join(" ")}`,
);
const process = cp.execFile(
entry.project.bscBinaryLocation,
callArgs,
{ cwd },
async (error, _stdout, stderr) => {
if (!error?.killed) {
if (debug())
console.log(
`Recompiled ${entry.file.sourceFileName} in ${
(performance.now() - startTime) / 1000
}s`,
);
getLogger().log(
`Recompiled ${entry.file.sourceFileName} in ${
(performance.now() - startTime) / 1000
}s`,
);
} else {
if (debug())
console.log(
`Compilation of ${entry.file.sourceFileName} was killed.`,
);
getLogger().log(
`Compilation of ${entry.file.sourceFileName} was killed.`,
);
}
let hasIgnoredErrorMessages = false;
if (
!error?.killed &&
triggerToken != null &&
verifyTriggerToken(entry.file.sourceFilePath, triggerToken)
) {
if (debug()) {
console.log("Resetting compilation status.");
}
getLogger().log("Resetting compilation status.");
// Reset compilation status as this compilation finished
entry.compilation = null;
const { result, codeActions } = await utils.parseCompilerLogOutput(
Expand Down Expand Up @@ -706,9 +682,7 @@ export function handleUpdateOpenedFile(
send: send,
onCompilationFinished?: () => void,
) {
if (debug()) {
console.log("Updated: " + filePath);
}
getLogger().log("Updated: " + filePath);
triggerIncrementalCompilationOfFile(
filePath,
fileContent,
Expand All @@ -718,9 +692,7 @@ export function handleUpdateOpenedFile(
}

export function handleClosedFile(filePath: NormalizedPath) {
if (debug()) {
console.log("Closed: " + filePath);
}
getLogger().log("Closed: " + filePath);
const entry = incrementallyCompiledFileInfo.get(filePath);
if (entry == null) return;
cleanUpIncrementalFiles(filePath, entry.project.rootPath);
Expand Down
Loading