Skip to content

Commit

Permalink
fix: Find sln/csproj from rootUri/rootPath
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Tao <[email protected]>
  • Loading branch information
tcx4c70 committed Aug 24, 2023
1 parent fa38981 commit 8bc48b9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
7 changes: 3 additions & 4 deletions src/CSharpLanguageServer/RoslynHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1028,16 +1028,15 @@ let findAndLoadSolutionOnDir (logMessage: AsyncLogFn) dir = async {
return solution
}

let loadSolutionOnSolutionPathOrCwd (logMessage: AsyncLogFn) solutionPathMaybe =
let loadSolutionOnSolutionPathOrDir (logMessage: AsyncLogFn) solutionPathMaybe rootPath =
match solutionPathMaybe with
| Some solutionPath -> async {
return! tryLoadSolutionOnPath logMessage solutionPath
}

| None -> async {
let cwd = Directory.GetCurrentDirectory()
do! logMessage (sprintf "attempting to find and load solution based on cwd (\"%s\").." cwd)
return! findAndLoadSolutionOnDir logMessage cwd
do! logMessage (sprintf "attempting to find and load solution based on root path (\"%s\").." rootPath)
return! findAndLoadSolutionOnDir logMessage rootPath
}

let getRoslynCodeActions (logMessage: AsyncLogFn) (doc: Document) (textSpan: TextSpan)
Expand Down
7 changes: 7 additions & 0 deletions src/CSharpLanguageServer/Server.fs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,13 @@ let setupServerHandlers settings (lspClient: LspClient) =

scope.Emit(ClientCapabilityChange p.Capabilities)

let rootPath =
p.RootUri
|> Option.map (fun uri -> Uri.UnescapeDataString(Uri(uri.Replace("%3a", ":", true, null)).LocalPath))
|> Option.orElse p.RootPath
|> Option.defaultValue (Directory.GetCurrentDirectory())
scope.Emit(RootPathChange rootPath)

// setup timer so actors get period ticks
setupTimer ()

Expand Down
9 changes: 8 additions & 1 deletion src/CSharpLanguageServer/State.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module CSharpLanguageServer.State

open System
open System.IO
open System.Threading
open Microsoft.CodeAnalysis
open Microsoft.CodeAnalysis.FindSymbols
Expand Down Expand Up @@ -41,6 +42,7 @@ type ServerRequest = {
}
and ServerState = {
Settings: ServerSettings
RootPath: string
ClientCapabilities: ClientCapabilities option
Solution: Solution option
OpenDocVersions: Map<string, int>
Expand Down Expand Up @@ -82,6 +84,7 @@ let pullNextRequestMaybe requestQueue =
(Some nextRequest, queueRemainder)

let emptyServerState = { Settings = emptySettings
RootPath = Directory.GetCurrentDirectory()
ClientCapabilities = None
Solution = None
OpenDocVersions = Map.empty
Expand All @@ -98,6 +101,7 @@ type ServerDocumentType =

type ServerStateEvent =
| SettingsChange of ServerSettings
| RootPathChange of string
| ClientCapabilityChange of ClientCapabilities option
| SolutionChange of Solution
| DecompiledMetadataAdd of string * DecompiledMetadataDocument
Expand Down Expand Up @@ -214,6 +218,9 @@ let processServerEvent (logMessage: AsyncLogFn) state postMsg msg: Async<ServerS

newState

| RootPathChange rootPath ->
return { state with RootPath = rootPath }

| ClientCapabilityChange cc ->
return { state with ClientCapabilities = cc }

Expand Down Expand Up @@ -251,7 +258,7 @@ let processServerEvent (logMessage: AsyncLogFn) state postMsg msg: Async<ServerS

match solutionReloadTime < DateTime.Now with
| true ->
let! newSolution = loadSolutionOnSolutionPathOrCwd logMessage state.Settings.SolutionPath
let! newSolution = loadSolutionOnSolutionPathOrDir logMessage state.Settings.SolutionPath state.RootPath

return { state with Solution = newSolution
SolutionReloadPending = None }
Expand Down

0 comments on commit 8bc48b9

Please sign in to comment.