Commit 1191301
Guard against workspace folders without a URI on initialize
When a client sends `workspaceFolders` on `initialize` and one of the
entries has no `uri`, the `OnInitialize` handler threw a
`NullReferenceException` while resolving the initial working directory
(`workspaceService.WorkspaceFolders.FirstOrDefault()?.Uri.GetFileSystemPath()`).
The `?.` only guarded the folder being null, not its `Uri`, so calling
`GetFileSystemPath()` on a null `Uri` blew up, the `initialize` response
was never returned, and the server was unusable for that client. The same
hazard exists in every other place we dereference `folder.Uri`
(`WorkspacePaths`, `GetRelativePath`, `FindFileInWorkspace`).
The issue (#2300) reports this as Linux-only with a repro that includes a
valid `uri`; that exact payload doesn't actually throw (I reproduced both
ways by driving a built PSES over stdio). The real trigger is a workspace
folder lacking a URI, which is what the captured stack trace
(`PsesLanguageServer.cs:line 150`) points at.
- Add `WorkspaceService.AddWorkspaceFolders`, which owns the invariant that
every folder in `WorkspaceFolders` has a non-null `Uri`. It skips null
folders and folders without a URI (logging a warning) and treats a null
collection as "no folders yet", falling back to the existing single-root
and CWD behavior.
- Call it from `OnInitialize` instead of the inline null-check plus
`AddRange`.
- Add a regression test covering null input and uriless/null folders.
Fixes #2300.
Drafted by Copilot (Claude Opus 4.8).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 6ad4f46 commit 1191301
3 files changed
Lines changed: 56 additions & 4 deletions
File tree
- src/PowerShellEditorServices
- Server
- Services/Workspace
- test/PowerShellEditorServices.Test/Session
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
140 | 140 | | |
141 | 141 | | |
142 | 142 | | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
| 143 | + | |
147 | 144 | | |
148 | 145 | | |
149 | 146 | | |
| |||
Lines changed: 29 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
109 | 138 | | |
110 | 139 | | |
111 | 140 | | |
| |||
Lines changed: 26 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
89 | 115 | | |
90 | 116 | | |
91 | 117 | | |
| |||
0 commit comments