Skip to content

Commit

Permalink
Null checks for various extension config things (#944)
Browse files Browse the repository at this point in the history
* null checks for various extension config things

* changelog
  • Loading branch information
zth authored Mar 7, 2024
1 parent 81427ec commit 155d23d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
## master

#### :bug: Bug Fix

- Fix null checks for editor config, so things don't blow up. https://github.com/rescript-lang/rescript-vscode/pull/944

## 1.44.0

#### :rocket: New Feature
Expand Down
8 changes: 4 additions & 4 deletions server/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ export type send = (msg: Message) => void;
export interface extensionConfiguration {
allowBuiltInFormatter: boolean;
askToStartBuild: boolean;
inlayHints: {
inlayHints?: {
enable: boolean;
maxLength: number | null;
};
codeLens: boolean;
binaryPath: string | null;
platformPath: string | null;
signatureHelp: {
signatureHelp?: {
enabled: boolean;
};
incrementalTypechecking: {
incrementalTypechecking?: {
enabled: boolean;
acrossFiles: boolean;
debugLogging: boolean;
Expand All @@ -40,7 +40,7 @@ let config: { extensionConfiguration: extensionConfiguration } = {
},
incrementalTypechecking: {
enabled: false,
acrossFiles: true,
acrossFiles: false,
debugLogging: true,
},
},
Expand Down
6 changes: 4 additions & 2 deletions server/src/incrementalCompilation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import * as c from "./constants";
import * as chokidar from "chokidar";

function debug() {
return config.extensionConfiguration.incrementalTypechecking.debugLogging;
return (
config.extensionConfiguration.incrementalTypechecking?.debugLogging ?? false
);
}

const INCREMENTAL_FOLDER_NAME = "___incremental";
Expand Down Expand Up @@ -420,7 +422,7 @@ async function figureOutBscArgs(entry: IncrementallyCompiledFileInfo) {

let callArgs: Array<string> = [];

if (config.extensionConfiguration.incrementalTypechecking.acrossFiles) {
if (config.extensionConfiguration.incrementalTypechecking?.acrossFiles) {
callArgs.push(
"-I",
path.resolve(entry.project.rootPath, INCREMENTAL_FILE_FOLDER_LOCATION)
Expand Down
12 changes: 6 additions & 6 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ let deleteProjectDiagnostics = (projectRootPath: string) => {
});

projectsFiles.delete(projectRootPath);
if (config.extensionConfiguration.incrementalTypechecking.enabled) {
if (config.extensionConfiguration.incrementalTypechecking?.enabled) {
ic.removeIncrementalFileFolder(projectRootPath);
}
}
Expand Down Expand Up @@ -239,7 +239,7 @@ let openedFile = (fileUri: string, fileContent: string) => {
if (projectRootPath != null) {
let projectRootState = projectsFiles.get(projectRootPath);
if (projectRootState == null) {
if (config.extensionConfiguration.incrementalTypechecking.enabled) {
if (config.extensionConfiguration.incrementalTypechecking?.enabled) {
ic.recreateIncrementalFileFolder(projectRootPath);
}
projectRootState = {
Expand Down Expand Up @@ -319,7 +319,7 @@ let openedFile = (fileUri: string, fileContent: string) => {
let closedFile = (fileUri: string) => {
let filePath = fileURLToPath(fileUri);

if (config.extensionConfiguration.incrementalTypechecking.enabled) {
if (config.extensionConfiguration.incrementalTypechecking?.enabled) {
ic.handleClosedFile(filePath);
}

Expand Down Expand Up @@ -349,7 +349,7 @@ let updateOpenedFile = (fileUri: string, fileContent: string) => {
let filePath = fileURLToPath(fileUri);
assert(stupidFileContentCache.has(filePath));
stupidFileContentCache.set(filePath, fileContent);
if (config.extensionConfiguration.incrementalTypechecking.enabled) {
if (config.extensionConfiguration.incrementalTypechecking?.enabled) {
ic.handleUpdateOpenedFile(filePath, fileContent, send, () => {
if (config.extensionConfiguration.codeLens) {
sendCodeLensRefresh();
Expand Down Expand Up @@ -418,7 +418,7 @@ function inlayHint(msg: p.RequestMessage) {
filePath,
params.range.start.line,
params.range.end.line,
config.extensionConfiguration.inlayHints.maxLength,
config.extensionConfiguration.inlayHints?.maxLength,
],
msg
);
Expand Down Expand Up @@ -794,7 +794,7 @@ function format(msg: p.RequestMessage): Array<p.Message> {
}

let updateDiagnosticSyntax = (fileUri: string, fileContent: string) => {
if (config.extensionConfiguration.incrementalTypechecking.enabled) {
if (config.extensionConfiguration.incrementalTypechecking?.enabled) {
// The incremental typechecking already sends syntax diagnostics.
return;
}
Expand Down

0 comments on commit 155d23d

Please sign in to comment.