Skip to content

Commit 03239c1

Browse files
committed
fix: renaming files and diagnostics on windows
1 parent 0250153 commit 03239c1

File tree

4 files changed

+24
-15
lines changed

4 files changed

+24
-15
lines changed

server/src/frameworks/Foundry/FoundryProject.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { OpenDocuments, ServerState } from "../../types";
1111
import { toUnixStyle } from "../../utils";
1212
import { directoryContains } from "../../utils/directoryContains";
1313
import { runCmd, runningOnWindows } from "../../utils/operatingSystem";
14+
import { toPath } from "../../utils/paths";
1415
import { CompilationDetails } from "../base/CompilationDetails";
1516
import { InitializationFailedError } from "../base/Errors";
1617
import { Project } from "../base/Project";
@@ -179,7 +180,11 @@ export class FoundryProject extends Project {
179180
for (const change of changes) {
180181
const remappingsPath = path.join(this.basePath, "remappings.txt");
181182

182-
if ([this.configPath, remappingsPath].some((uri) => change.uri === uri)) {
183+
if (
184+
[this.configPath, remappingsPath].some(
185+
(filePath) => toPath(change.uri) === filePath
186+
)
187+
) {
183188
this.serverState.logger.info(
184189
`Reinitializing foundry project: ${this.id()}`
185190
);

server/src/frameworks/Hardhat/HardhatProject.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { TextDocument } from "vscode-languageserver-textdocument";
1515
import { OpenDocuments, ServerState } from "../../types";
1616
import { directoryContains } from "../../utils/directoryContains";
1717
import { Logger } from "../../utils/Logger";
18+
import { toPath } from "../../utils/paths";
1819
import { CompilationDetails } from "../base/CompilationDetails";
1920
import { InitializationFailedError } from "../base/Errors";
2021
import { FileBelongsResult, Project } from "../base/Project";
@@ -199,7 +200,7 @@ export class HardhatProject extends Project {
199200
if (this._isWorkerRunning()) {
200201
this.workerProcess!.send(new InvalidateBuildCacheMessage());
201202
}
202-
} else if (change.uri === this.configPath) {
203+
} else if (toPath(change.uri) === this.configPath) {
203204
this.logger.info(`Config file changed. Restarting worker process.`);
204205

205206
// Kill existing worker process

server/src/services/documents/onDidChangeWatchedFiles.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,27 @@ import {
33
FileChangeType,
44
} from "vscode-languageserver";
55
import { ServerState } from "../../types";
6-
import { decodeUriAndRemoveFilePrefix } from "../../utils";
6+
import { toUnixStyle } from "../../utils";
77
import { clearDiagnostics } from "../validation/validate";
88

99
export function onDidChangeWatchedFiles(serverState: ServerState) {
1010
return async (params: DidChangeWatchedFilesParams) => {
11-
// Normalize file uris
12-
const normalizedParams = {
13-
changes: params.changes.map((change) => ({
14-
...change,
15-
uri: decodeUriAndRemoveFilePrefix(change.uri),
16-
})),
17-
};
18-
1911
// Index new solidity files
20-
for (const change of normalizedParams.changes) {
12+
for (const change of params.changes) {
2113
if (
2214
change.uri.endsWith(".sol") &&
2315
change.type === FileChangeType.Deleted
2416
) {
25-
delete serverState.solFileIndex[change.uri];
26-
await clearDiagnostics(serverState, change.uri);
17+
const unixStyleUri = toUnixStyle(change.uri);
18+
19+
delete serverState.solFileIndex[unixStyleUri];
20+
await clearDiagnostics(serverState, unixStyleUri);
2721
}
2822
}
2923

3024
// Notify all registered projects of the file changes
3125
for (const project of Object.values(serverState.projects)) {
32-
await project.onWatchedFilesChanges(normalizedParams);
26+
await project.onWatchedFilesChanges(params);
3327
}
3428
};
3529
}

server/src/utils/paths.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { URI } from "vscode-uri";
2+
3+
export function toPath(uri: string) {
4+
return URI.parse(uri).fsPath;
5+
}
6+
7+
export function toUri(path: string) {
8+
return URI.file(path);
9+
}

0 commit comments

Comments
 (0)