Skip to content

Commit bf9a55d

Browse files
rtboWebFreak001
authored andcommitted
normalize uri and CCDB filename on Windows
drive letter is now always lower case
1 parent 39ebdda commit bf9a55d

File tree

2 files changed

+26
-7
lines changed
  • protocol/source/served/lsp
  • workspace-d/source/workspaced/com

2 files changed

+26
-7
lines changed

protocol/source/served/lsp/uri.d

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ DocumentUri uriFromFile(scope const(char)[] file)
1919
if ((!isAbsolute(file) && !file.startsWith("/"))
2020
|| !file.length)
2121
throw new Exception(text("Tried to pass relative path '", file, "' to uriFromFile"));
22-
file = file.buildNormalizedPath.replace("\\", "/");
22+
file = file.buildNormalizedPath();
23+
version(Windows)
24+
{
25+
file = file.replace("\\", "/");
26+
file = driveName(file).toLower() ~ stripDrive(file);
27+
}
2328
assert(file.length);
2429
if (file.ptr[0] != '/')
2530
file = '/' ~ file; // always triple slash at start but never quad slash
@@ -34,7 +39,7 @@ unittest
3439

3540
version (Windows)
3641
{
37-
42+
assertEquals(uriFromFile(`C:\Home\foo\bar.d`), `file://c%3A/Home/foo/bar.d`);
3843
}
3944
else
4045
{
@@ -283,7 +288,7 @@ unittest
283288
{
284289
assertEquals(uriNormalize(`b/../a.d`), `a.d`);
285290
assertEquals(uriNormalize(`b/../../a.d`), `../a.d`);
286-
291+
287292
foreach (prefix; ["file:///", "file://", "", "/", "//"])
288293
{
289294
assertEquals(uriNormalize(prefix ~ `foo/bar/./a.d`), prefix ~ `foo/bar/a.d`);

workspace-d/source/workspaced/com/ccdb.d

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module workspaced.com.ccdb;
66
import std.exception;
77
import std.json;
88
import std.path;
9+
import std.string;
910
import fs = std.file;
1011

1112
import workspaced.api;
@@ -144,7 +145,7 @@ class ClangCompilationDatabaseComponent : ComponentWrapper
144145
/// in the database.
145146
CompileCommand getCompileCommand(string filename) @property
146147
{
147-
auto normalized = buildNormalizedPath(filename);
148+
const normalized = normalizedCcdbPath(filename);
148149
auto ccp = normalized in _compileCommands;
149150
if (ccp)
150151
return *ccp;
@@ -171,8 +172,10 @@ public class CompileCommand
171172
import std.algorithm : map;
172173
import std.array : array;
173174

174-
this.directory = enforce("directory" in json, "'directory' missing from Clang compilation database entry")
175-
.str;
175+
this.directory = normalizedCcdbPath(
176+
enforce("directory" in json, "'directory' missing from Clang compilation database entry")
177+
.str
178+
);
176179
this.file = enforce("file" in json, "'file' missing from Clang compilation database entry")
177180
.str;
178181

@@ -209,7 +212,7 @@ public class CompileCommand
209212

210213
string getNormalizedFilePath() const
211214
{
212-
return getPath(file).buildNormalizedPath();
215+
return normalizedCcdbPath(getPath(file));
213216
}
214217

215218
string getPath(string filename) const
@@ -303,6 +306,17 @@ public class CompileCommand
303306
}
304307
}
305308

309+
string normalizedCcdbPath(string filePath)
310+
{
311+
const normalized = filePath.buildNormalizedPath();
312+
// Let the drive be lower case on Windows (not handled by buildNormalizedPath).
313+
// This is needed because commands are resolved by simple string comparison.
314+
version (Windows)
315+
return driveName(normalized).toLower() ~ stripDrive(normalized);
316+
else
317+
return normalized;
318+
}
319+
306320
void feedOptions(
307321
in CompileCommand cc,
308322
ref HashSet!string imports,

0 commit comments

Comments
 (0)