Skip to content

Commit 7334e1e

Browse files
committed
Always override default config
1 parent 4c915ba commit 7334e1e

File tree

2 files changed

+41
-31
lines changed

2 files changed

+41
-31
lines changed

server/src/config.ts

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,34 +29,36 @@ export interface extensionConfiguration {
2929
};
3030
}
3131

32-
// All values here are temporary, and will be overridden as the server is
33-
// initialized, and the current config is received from the client.
34-
let config: { extensionConfiguration: extensionConfiguration } = {
35-
extensionConfiguration: {
36-
askToStartBuild: true,
37-
logLevel: "info",
38-
inlayHints: {
39-
enable: false,
40-
maxLength: 25,
41-
},
42-
codeLens: false,
43-
binaryPath: null,
44-
platformPath: null,
45-
signatureHelp: {
46-
enabled: true,
47-
forConstructorPayloads: true,
48-
},
49-
incrementalTypechecking: {
32+
export const initialConfiguration: extensionConfiguration = {
33+
askToStartBuild: true,
34+
logLevel: "info",
35+
inlayHints: {
36+
enable: false,
37+
maxLength: 25,
38+
},
39+
codeLens: false,
40+
binaryPath: null,
41+
platformPath: null,
42+
signatureHelp: {
43+
enabled: true,
44+
forConstructorPayloads: true,
45+
},
46+
incrementalTypechecking: {
47+
enable: true,
48+
acrossFiles: false,
49+
debugLogging: false,
50+
},
51+
cache: {
52+
projectConfig: {
5053
enable: true,
51-
acrossFiles: false,
52-
debugLogging: false,
53-
},
54-
cache: {
55-
projectConfig: {
56-
enable: true,
57-
},
5854
},
5955
},
6056
};
6157

58+
// All values here are temporary, and will be overridden as the server is
59+
// initialized, and the current config is received from the client.
60+
let config: { extensionConfiguration: extensionConfiguration } = {
61+
extensionConfiguration: initialConfiguration,
62+
};
63+
6264
export default config;

server/src/server.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,19 @@ import { assert } from "console";
2626
import { WorkspaceEdit } from "vscode-languageserver";
2727
import { onErrorReported } from "./errorReporter";
2828
import * as ic from "./incrementalCompilation";
29-
import config, { extensionConfiguration } from "./config";
29+
import config, { extensionConfiguration, initialConfiguration } from "./config";
3030
import { projectsFiles } from "./projectFiles";
3131
import { NormalizedPath } from "./utils";
3232
import { initializeLogger, getLogger, setLogLevel, LogLevel } from "./logger";
3333

34-
function applyLogLevel(configuration: extensionConfiguration) {
34+
function applyUserConfiguration(configuration: extensionConfiguration) {
35+
// We always want to spread the initial configuration to ensure all defaults are respected.
36+
config.extensionConfiguration = Object.assign(
37+
{},
38+
initialConfiguration,
39+
configuration,
40+
);
41+
3542
const debugLoggingEnabled =
3643
configuration.incrementalTypechecking?.debugLogging === true;
3744

@@ -538,6 +545,9 @@ let closedFile = async (fileUri: utils.FileURI) => {
538545
};
539546

540547
let updateOpenedFile = (fileUri: utils.FileURI, fileContent: string) => {
548+
getLogger().info(
549+
`Updating opened file ${fileUri}, incremental TC enabled: ${config.extensionConfiguration.incrementalTypechecking?.enable}`,
550+
);
541551
let filePath = utils.uriToNormalizedPath(fileUri);
542552
assert(stupidFileContentCache.has(filePath));
543553
stupidFileContentCache.set(filePath, fileContent);
@@ -1488,8 +1498,7 @@ async function onMessage(msg: p.Message) {
14881498
?.extensionConfiguration as extensionConfiguration | undefined;
14891499

14901500
if (initialConfiguration != null) {
1491-
config.extensionConfiguration = initialConfiguration;
1492-
applyLogLevel(initialConfiguration);
1501+
applyUserConfiguration(initialConfiguration);
14931502
}
14941503

14951504
// These are static configuration options the client can set to enable certain
@@ -1699,8 +1708,7 @@ async function onMessage(msg: p.Message) {
16991708
extensionConfiguration | null | undefined,
17001709
];
17011710
if (configuration != null) {
1702-
config.extensionConfiguration = configuration;
1703-
applyLogLevel(configuration);
1711+
applyUserConfiguration(configuration);
17041712
}
17051713
}
17061714
} else if (

0 commit comments

Comments
 (0)