Skip to content
This repository was archived by the owner on Nov 4, 2024. It is now read-only.

Commit fa56776

Browse files
authored
Allow root to be null (microsoft#994)
Fixes microsoft#977. This is a weird case, but did work before my search path cleanups. Revert to the old behavior when the root is set to `null`. To test, open VS Code and close any folders, make a new file and switch its language mode to Python.
1 parent 985da84 commit fa56776

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/LanguageServer/Impl/Implementation/Server.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,10 @@ public async Task<InitializeResult> InitializeAsync(InitializeParams @params, Ca
104104
_rdt = _services.GetService<IRunningDocumentTable>();
105105

106106
_rootDir = @params.rootUri != null ? @params.rootUri.ToAbsolutePath() : @params.rootPath;
107-
_rootDir = PathUtils.NormalizePath(_rootDir);
108-
_rootDir = PathUtils.TrimEndSeparator(_rootDir);
107+
if (_rootDir != null) {
108+
_rootDir = PathUtils.NormalizePath(_rootDir);
109+
_rootDir = PathUtils.TrimEndSeparator(_rootDir);
110+
}
109111

110112
Version.TryParse(@params.initializationOptions.interpreter.properties?.Version, out var version);
111113

@@ -116,14 +118,14 @@ public async Task<InitializeResult> InitializeAsync(InitializeParams @params, Ca
116118
) {
117119
// 1) Split on ';' to support older VS Code extension versions which send paths as a single entry separated by ';'. TODO: Eventually remove.
118120
// 2) Normalize paths.
119-
// 3) If a path isn't rooted, then root it relative to the workspace root.
121+
// 3) If a path isn't rooted, then root it relative to the workspace root. If _rootDir is null, then accept the path as-is.
120122
// 4) Trim off any ending separator for a consistent style.
121123
// 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).
122124
// 6) Remove duplicates.
123125
SearchPaths = @params.initializationOptions.searchPaths
124126
.Select(p => p.Split(';', StringSplitOptions.RemoveEmptyEntries)).SelectMany()
125127
.Select(PathUtils.NormalizePath)
126-
.Select(p => Path.IsPathRooted(p) ? p : Path.GetFullPath(p, _rootDir))
128+
.Select(p => _rootDir == null || Path.IsPathRooted(p) ? p : Path.GetFullPath(p, _rootDir))
127129
.Select(PathUtils.TrimEndSeparator)
128130
.Where(p => !string.IsNullOrWhiteSpace(p) && p != "/" && !p.PathEquals(_rootDir))
129131
.Distinct(PathEqualityComparer.Instance)

src/LanguageServer/Impl/Indexing/IndexManager.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ internal class IndexManager : IIndexManager {
4242
public IndexManager(IFileSystem fileSystem, PythonLanguageVersion version, string rootPath, string[] includeFiles,
4343
string[] excludeFiles, IIdleTimeService idleTimeService) {
4444
Check.ArgumentNotNull(nameof(fileSystem), fileSystem);
45-
Check.ArgumentNotNull(nameof(rootPath), rootPath);
4645
Check.ArgumentNotNull(nameof(includeFiles), includeFiles);
4746
Check.ArgumentNotNull(nameof(excludeFiles), excludeFiles);
4847
Check.ArgumentNotNull(nameof(idleTimeService), idleTimeService);

0 commit comments

Comments
 (0)