|
15 | 15 |
|
16 | 16 | using System;
|
17 | 17 | using System.Diagnostics;
|
| 18 | +using System.IO; |
18 | 19 | using System.Linq;
|
19 | 20 | using System.Reflection;
|
20 | 21 | using System.Threading;
|
@@ -102,17 +103,31 @@ public async Task<InitializeResult> InitializeAsync(InitializeParams @params, Ca
|
102 | 103 | _services.AddService(new RunningDocumentTable(_services));
|
103 | 104 | _rdt = _services.GetService<IRunningDocumentTable>();
|
104 | 105 |
|
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 | + |
106 | 110 | Version.TryParse(@params.initializationOptions.interpreter.properties?.Version, out var version);
|
107 | 111 |
|
108 | 112 | var configuration = new InterpreterConfiguration(null, null,
|
109 | 113 | interpreterPath: @params.initializationOptions.interpreter.properties?.InterpreterPath,
|
110 | 114 | moduleCachePath: @params.initializationOptions.interpreter.properties?.DatabasePath,
|
111 | 115 | version: version
|
112 | 116 | ) {
|
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(), |
116 | 131 | TypeshedPath = @params.initializationOptions.typeStubSearchPaths.FirstOrDefault()
|
117 | 132 | };
|
118 | 133 |
|
|
0 commit comments