Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletions src/Core/Project.fs
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,8 @@ module Project =
let setContext (context: ExtensionContext) =
extensionWorkspaceState <- Some context.workspaceState

let private parse (value: string) =
let fullPath = node.path.resolve (workspace.rootPath.Value, value)
let private parseWithBase (basePath: string) (value: string) =
let fullPath = node.path.resolve (basePath, value)

if value.ToLowerInvariant().EndsWith(".sln") then
ConfiguredWorkspace.Solution fullPath
Expand All @@ -340,16 +340,39 @@ module Project =
with _ ->
false

/// Returns all candidate base paths for resolving a relative workspace path.
/// In a multi-folder workspace, rootPath is the first folder. We try all
/// workspace folders so that a relative path like "backend/app.sln" works
/// even when the F# folder is not the first workspace folder.
let private candidateBasePaths () =
let rootPaths = workspace.rootPath |> Option.toList

let folderPaths =
workspace.workspaceFolders
|> Option.map (fun folders -> folders |> Seq.toList |> List.map (fun f -> f.uri.fsPath))
|> Option.defaultValue []

(rootPaths @ folderPaths) |> List.distinct

let private parseAndValidate (config: string option) =
match config with
| None
| Some "" -> None
| Some ws ->
let configured = parse ws
let candidates = candidateBasePaths ()

let found =
candidates
|> List.tryPick (fun basePath ->
let configured = parseWithBase basePath ws
if pathExists configured then Some configured else None)

match found with
| Some _ -> found
| None ->
let firstBase = candidates |> List.tryHead |> Option.defaultValue ""
let configured = parseWithBase firstBase ws

if pathExists configured then
Some configured
else
logger.Warn(
"Ignoring configured workspace '%s' as the file or directory can't be resolved (From '%s')",
ws,
Expand Down
Loading