Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Commit cc7d4f7

Browse files
authored
Preprocess search paths (#966)
* preprocess search paths * remove wait for debugger * ignore /
1 parent e7bba34 commit cc7d4f7

File tree

1 file changed

+19
-4
lines changed
  • src/LanguageServer/Impl/Implementation

1 file changed

+19
-4
lines changed

src/LanguageServer/Impl/Implementation/Server.cs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
using System;
1717
using System.Diagnostics;
18+
using System.IO;
1819
using System.Linq;
1920
using System.Reflection;
2021
using System.Threading;
@@ -102,17 +103,31 @@ public async Task<InitializeResult> InitializeAsync(InitializeParams @params, Ca
102103
_services.AddService(new RunningDocumentTable(_services));
103104
_rdt = _services.GetService<IRunningDocumentTable>();
104105

105-
_rootDir = @params.rootUri != null ? @params.rootUri.ToAbsolutePath() : PathUtils.NormalizePath(@params.rootPath);
106+
_rootDir = @params.rootUri != null ? @params.rootUri.ToAbsolutePath() : @params.rootPath;
107+
_rootDir = PathUtils.NormalizePath(_rootDir);
108+
_rootDir = PathUtils.TrimEndSeparator(_rootDir);
109+
106110
Version.TryParse(@params.initializationOptions.interpreter.properties?.Version, out var version);
107111

108112
var configuration = new InterpreterConfiguration(null, null,
109113
interpreterPath: @params.initializationOptions.interpreter.properties?.InterpreterPath,
110114
moduleCachePath: @params.initializationOptions.interpreter.properties?.DatabasePath,
111115
version: version
112116
) {
113-
// TODO: Remove this split once the extension is updated and no longer passes the interpreter search paths directly.
114-
// This is generally harmless to keep around.
115-
SearchPaths = @params.initializationOptions.searchPaths.Select(p => p.Split(';', StringSplitOptions.RemoveEmptyEntries)).SelectMany().ToList(),
117+
// 1) Split on ';' to support older VS Code extension versions which send paths as a single entry separated by ';'. TODO: Eventually remove.
118+
// 2) Normalize paths.
119+
// 3) If a path isn't rooted, then root it relative to the workspace root.
120+
// 4) Trim off any ending separator for a consistent style.
121+
// 5) Filter out any entries which are the same as the workspace root; they are redundant. Also ignore "/" to work around the extension (for now).
122+
// 6) Remove duplicates.
123+
SearchPaths = @params.initializationOptions.searchPaths
124+
.Select(p => p.Split(';', StringSplitOptions.RemoveEmptyEntries)).SelectMany()
125+
.Select(PathUtils.NormalizePath)
126+
.Select(p => Path.IsPathRooted(p) ? p : Path.GetFullPath(p, _rootDir))
127+
.Select(PathUtils.TrimEndSeparator)
128+
.Where(p => !string.IsNullOrWhiteSpace(p) && p != "/" && !p.PathEquals(_rootDir))
129+
.Distinct(PathEqualityComparer.Instance)
130+
.ToList(),
116131
TypeshedPath = @params.initializationOptions.typeStubSearchPaths.FirstOrDefault()
117132
};
118133

0 commit comments

Comments
 (0)