Skip to content

Commit 1c07abf

Browse files
committed
try to not break encapsulation
1 parent d29187d commit 1c07abf

File tree

3 files changed

+47
-26
lines changed

3 files changed

+47
-26
lines changed

client/src/extension.ts

+8
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,14 @@ export function activate(context: ExtensionContext) {
248248
// language client, and because of that requires a full restart.
249249
context.subscriptions.push(
250250
workspace.onDidChangeConfiguration(({ affectsConfiguration }) => {
251+
// Send a general message that configuration has updated. Clients
252+
// interested can then pull the new configuration as they see fit.
253+
client
254+
.sendNotification("workspace/didChangeConfiguration")
255+
.catch((err) => {
256+
window.showErrorMessage(String(err));
257+
});
258+
251259
// Put any configuration that, when changed, requires a full restart of
252260
// the server here. That will typically be any configuration that affects
253261
// the capabilities declared by the server, since those cannot be updated

server/src/server.ts

+24-24
Original file line numberDiff line numberDiff line change
@@ -741,10 +741,30 @@ function format(msg: p.RequestMessage): Array<p.Message> {
741741
let bscBinaryPath =
742742
projectRootPath === null ? null : findBscBinary(projectRootPath);
743743

744-
if (
745-
bscBinaryPath == null &&
746-
!extensionConfiguration.allowBuiltInFormatter
747-
) {
744+
let formattedResult = utils.formatCode(
745+
bscBinaryPath,
746+
filePath,
747+
code,
748+
extensionConfiguration.allowBuiltInFormatter
749+
);
750+
if (formattedResult.kind === "success") {
751+
let max = code.length;
752+
let result: p.TextEdit[] = [
753+
{
754+
range: {
755+
start: { line: 0, character: 0 },
756+
end: { line: max, character: max },
757+
},
758+
newText: formattedResult.result,
759+
},
760+
];
761+
let response: p.ResponseMessage = {
762+
jsonrpc: c.jsonrpcVersion,
763+
id: msg.id,
764+
result: result,
765+
};
766+
return [response];
767+
} else if (formattedResult.kind === "blocked-using-built-in-formatter") {
748768
// Let's only prompt the user once about this, or things might become annoying.
749769
if (hasPromptedAboutBuiltInFormatter) {
750770
return [fakeSuccessResponse];
@@ -763,26 +783,6 @@ function format(msg: p.RequestMessage): Array<p.Message> {
763783
params: params,
764784
};
765785
return [fakeSuccessResponse, response];
766-
}
767-
768-
let formattedResult = utils.formatCode(bscBinaryPath, filePath, code);
769-
if (formattedResult.kind === "success") {
770-
let max = code.length;
771-
let result: p.TextEdit[] = [
772-
{
773-
range: {
774-
start: { line: 0, character: 0 },
775-
end: { line: max, character: max },
776-
},
777-
newText: formattedResult.result,
778-
},
779-
];
780-
let response: p.ResponseMessage = {
781-
jsonrpc: c.jsonrpcVersion,
782-
id: msg.id,
783-
result: result,
784-
};
785-
return [response];
786786
} else {
787787
// let the diagnostics logic display the updated syntax errors,
788788
// from the build.

server/src/utils.ts

+15-2
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,18 @@ type execResult =
7575
error: string;
7676
};
7777

78+
type formatCodeResult =
79+
| execResult
80+
| {
81+
kind: "blocked-using-built-in-formatter";
82+
};
83+
7884
export let formatCode = (
7985
bscPath: p.DocumentUri | null,
8086
filePath: string,
81-
code: string
82-
): execResult => {
87+
code: string,
88+
allowBuiltInFormatter: boolean
89+
): formatCodeResult => {
8390
let extension = path.extname(filePath);
8491
let formatTempFileFullPath = createFileInTempDir(extension);
8592
fs.writeFileSync(formatTempFileFullPath, code, {
@@ -100,6 +107,12 @@ export let formatCode = (
100107
result: result.toString(),
101108
};
102109
} else {
110+
if (!allowBuiltInFormatter) {
111+
return {
112+
kind: "blocked-using-built-in-formatter",
113+
};
114+
}
115+
103116
let result = runAnalysisAfterSanityCheck(
104117
formatTempFileFullPath,
105118
["format", formatTempFileFullPath],

0 commit comments

Comments
 (0)