Skip to content

Commit

Permalink
Fix #256 Clear validator configurations before retrieving new ones
Browse files Browse the repository at this point in the history
Signed-off-by: Remy Suen <[email protected]>
  • Loading branch information
rcjsuen committed Apr 12, 2021
1 parent 764287f commit 6240cd6
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog
All notable changes to this project will be documented in this file.

## [0.4.1] - 2021-04-12
### Fixed
- textDocument/publishDiagnostics
- fixed a regression that caused the internal state of configurations to be stale which mean editors would not immediately be notified of changed diagnostics based on configuration changes ([#256](https://github.com/rcjsuen/dockerfile-language-server-nodejs/issues/256))

## [0.4.0] - 2021-04-11
### Added
- settings
Expand Down
3 changes: 2 additions & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,8 @@ function refreshFormatterConfigurations() {
function refreshValidatorConfigurations() {
// store all the URIs that need to be refreshed
const settingsRequest = getConfigurationItems("docker.languageserver.diagnostics");

// clear the cache
validatorConfigurations.clear();
// ask the workspace for the configurations
connection.workspace.getConfiguration(settingsRequest).then((values: ValidatorConfiguration[]) => {
const toRevalidate: string[] = [];
Expand Down
135 changes: 135 additions & 0 deletions test/serverConfiguration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* ------------------------------------------------------------------------------------------ */
import * as child_process from "child_process";
import * as assert from "assert";
import { DiagnosticSeverity } from "vscode-languageserver";

// fork the server and connect to it using Node IPC
const lspProcess = child_process.fork("out/src/server.js", [ "--node-ipc" ]);
Expand Down Expand Up @@ -274,6 +275,140 @@ describe("LSP server with configuration support", function() {
});
});


function test256(fileName: string, initialSeverity: string, severity: string, callback: Function): void {
let firstConfigurationRequest = true;
const configurationListener = (json: any) => {
if (json.method === "workspace/configuration" && json.params.items.length > 0 && json.params.items[0].section === "docker.languageserver.diagnostics") {
if (firstConfigurationRequest) {
if (initialSeverity === null) {
sendResult(json.id, [{ }]);
} else {
sendResult(json.id, [{ instructionJSONInSingleQuotes: initialSeverity }]);
}
firstConfigurationRequest = false;
} else {
if (severity === null) {
sendResult(json.id, [{ }]);
} else {
sendResult(json.id, [{ instructionJSONInSingleQuotes: severity }]);
}
lspProcess.removeListener("message", configurationListener);
}
}
};
lspProcess.on("message", configurationListener);

const documentURI = "uri://dockerfile/" + fileName;
let first = true;
const listener256 = (json: any) => {
if (json.method === "textDocument/publishDiagnostics" &&
json.params.uri === documentURI) {
if (first) {
if (initialSeverity === null || initialSeverity === "ignore") {
assert.equal(json.params.diagnostics.length, 0);
} else {
assert.equal(json.params.diagnostics.length, 1);
assert.equal(json.params.diagnostics[0].severity, DiagnosticSeverity.Warning);
}
first = false;

if (severity === null) {
sendNotification("workspace/didChangeConfiguration", {
settings: {
}
});
} else {
sendNotification("workspace/didChangeConfiguration", {
settings: {
docker: {
languageserver: {
diagnostics: {
instructionJSONInSingleQuotes: severity
}
}
}
}
});
}
} else {
lspProcess.removeListener("message", listener256);
if (severity === "ignore") {
assert.equal(json.params.diagnostics.length, 0);
} else {
if (severity === null) {
assert.equal(json.params.diagnostics.length, 0);
} else {
if (severity === "error") {
assert.equal(json.params.diagnostics[0].severity, DiagnosticSeverity.Error);
} else {
assert.equal(json.params.diagnostics[0].severity, DiagnosticSeverity.Warning);
}
assert.equal(json.params.diagnostics.length, 1);
}
}
sendNotification("textDocument/didClose", {
textDocument: {
uri: documentURI
}
});
callback();
}
}
};
lspProcess.on("message", listener256);

if (severity === null) {
sendNotification("workspace/didChangeConfiguration", {
settings: {
}
});
} else {
sendNotification("workspace/didChangeConfiguration", {
settings: {
docker: {
languageserver: {
diagnostics: {
instructionJSONInSingleQuotes: severity
}
}
}
}
});
}

sendNotification("textDocument/didOpen", {
textDocument: {
languageId: "dockerfile",
version: 1,
uri: documentURI,
text: "FROM node\nRUN ['a']"
}
});
}

describe("issue #256 file configuration", () => {
it("null to ignore configuration", function(finished) {
this.timeout(5000);
test256("256-null-to-ignore", null, "ignore", finished);
});

it("ignore to null configuration", function(finished) {
this.timeout(5000);
test256("256-ignore-to-null", "ignore", null, finished);
});

it("ignore to warning configuration", function(finished) {
this.timeout(5000);
test256("256-ignore-to-warning", "ignore", "warning", finished);
});

it("ignore to error configuration", function(finished) {
this.timeout(5000);
test256("256-ignore-to-error","ignore", "error", finished);
});
});

after(() => {
// terminate the forked LSP process after all the tests have been run
lspProcess.kill();
Expand Down

0 comments on commit 6240cd6

Please sign in to comment.