Skip to content

Commit ecfbbf8

Browse files
[Repo Assist] fix: handle None workspace.rootPath in FSI and Diagnostics commands (#2162)
* fix: handle None workspace.rootPath in FSI and Diagnostics commands In multi-root workspaces, workspace.rootPath is None (undefined in JavaScript), so using workspace.rootPath.Value throws at runtime. This affects two code paths: 1. Fsi.fs sendCd fallback: when there is no active text editor and FSI needs a working directory, it would crash instead of falling back to a sensible directory. 2. Fsi.fs generateProjectReferencesForProject: calling 'FSI: Generate project references' in a multi-root workspace would crash instead of creating the references.fsx document. 3. Diagnostics.fs writeToFile: running 'F#: Get diagnostic info' in a multi-root workspace would crash instead of opening the info file. Fix: use workspace.rootPath first; fall back to the first workspace folder if available; fall back to the OS temp directory as a last resort. Co-authored-by: Copilot <[email protected]> * ci: trigger checks --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Copilot <[email protected]>
1 parent 40683b2 commit ecfbbf8

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

src/Components/Diagnostics.fs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,15 @@ Error: %A
110110

111111
let writeToFile (text: string) =
112112
promise {
113-
let path = node.path.join (workspace.rootPath.Value, "Diagnostic info")
113+
let workspaceRoot =
114+
workspace.rootPath
115+
|> Option.defaultWith (fun () ->
116+
workspace.workspaceFolders
117+
|> Option.bind (fun folders ->
118+
if folders.Count > 0 then Some(string folders.[0].uri.fsPath) else None)
119+
|> Option.defaultValue (node.os.tmpdir ()))
120+
121+
let path = node.path.join (workspaceRoot, "Diagnostic info")
114122
let newFile = vscode.Uri.parse ("untitled:" + path)
115123
let! document = newFile |> workspace.openTextDocument
116124

src/Components/Fsi.fs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,14 @@ module Fsi =
331331
file, dir, line
332332

333333
| None ->
334-
let dir = workspace.rootPath.Value
334+
let dir =
335+
workspace.rootPath
336+
|> Option.defaultWith (fun () ->
337+
workspace.workspaceFolders
338+
|> Option.bind (fun folders ->
339+
if folders.Count > 0 then Some(string folders.[0].uri.fsPath) else None)
340+
|> Option.defaultValue (node.os.tmpdir ()))
341+
335342
node.path.join (dir, "tmp.fsx"), dir, 1
336343

337344
match lastCd with
@@ -666,7 +673,15 @@ module Fsi =
666673
let ctn = fsiInitCommandsForProject project
667674

668675
promise {
669-
let path = node.path.join (workspace.rootPath.Value, "references.fsx")
676+
let workspaceRoot =
677+
workspace.rootPath
678+
|> Option.defaultWith (fun () ->
679+
workspace.workspaceFolders
680+
|> Option.bind (fun folders ->
681+
if folders.Count > 0 then Some(string folders.[0].uri.fsPath) else None)
682+
|> Option.defaultValue (node.os.tmpdir ()))
683+
684+
let path = node.path.join (workspaceRoot, "references.fsx")
670685

671686
let! td = vscode.Uri.parse ("untitled:" + path) |> workspace.openTextDocument
672687

0 commit comments

Comments
 (0)