Skip to content

Commit 5526c94

Browse files
committed
codebase?
1 parent e691b5f commit 5526c94

File tree

5 files changed

+70
-31
lines changed

5 files changed

+70
-31
lines changed

src/CSharpLanguageServer/CSharpLanguageServer.fsproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@
3030
<Compile Include="Roslyn/Document.fs" />
3131
<Compile Include="Roslyn/Symbol.fs" />
3232
<Compile Include="DocumentationUtil.fs" />
33-
<Compile Include="Diagnostics.fs" />
3433
<Compile Include="Lsp/Client.fs" />
34+
<Compile Include="State/Codebase.fs" />
3535
<Compile Include="State/ServerState.fs" />
3636
<Compile Include="State/ServerRequestContext.fs" />
37+
<Compile Include="Diagnostics.fs" />
3738
<Compile Include="Handlers/CSharpMetadata.fs" />
3839
<Compile Include="Handlers/CallHierarchy.fs" />
3940
<Compile Include="Handlers/CodeAction.fs" />

src/CSharpLanguageServer/Diagnostics.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ open Ionide.LanguageServerProtocol.JsonRpc
99
open CSharpLanguageServer.Types
1010
open CSharpLanguageServer.Logging
1111
open CSharpLanguageServer.Roslyn.Solution
12+
open CSharpLanguageServer.Roslyn.Codebase
1213

1314
module Diagnostics =
1415
let private logger = Logging.getLoggerByName "Diagnostics"
@@ -64,7 +65,7 @@ module Diagnostics =
6465

6566
let lspClient = new LspClientStub()
6667
let cwd = string (Directory.GetCurrentDirectory())
67-
let! _sln = solutionLoadSolutionWithPathOrOnCwd lspClient None cwd
68+
let! codebase = Codebase.solutionLoadSolutionWithPathOrOnCwd lspClient None cwd
6869

6970
logger.LogDebug("diagnose: done")
7071

src/CSharpLanguageServer/Roslyn/Solution.fs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -376,27 +376,6 @@ let solutionFindAndLoadOnDir (lspClient: ILspClient) dir = async {
376376
}
377377

378378

379-
let solutionLoadSolutionWithPathOrOnCwd (lspClient: ILspClient) (solutionPathMaybe: string option) (cwd: string) =
380-
match solutionPathMaybe with
381-
| Some solutionPath -> async {
382-
let rootedSolutionPath =
383-
match Path.IsPathRooted solutionPath with
384-
| true -> solutionPath
385-
| false -> Path.Combine(cwd, solutionPath)
386-
387-
return! solutionTryLoadOnPath lspClient rootedSolutionPath
388-
}
389-
390-
| None -> async {
391-
let logMessage: LogMessageParams =
392-
{ Type = MessageType.Info
393-
Message = sprintf "csharp-ls: attempting to find and load solution based on cwd (\"%s\").." cwd }
394-
395-
do! lspClient.WindowLogMessage logMessage
396-
return! solutionFindAndLoadOnDir lspClient cwd
397-
}
398-
399-
400379
let solutionGetRazorDocumentForUri
401380
(solution: Solution)
402381
(uri: string)
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
namespace CSharpLanguageServer.State
2+
3+
open System
4+
open System.IO
5+
open System.Threading
6+
open System.Collections.Generic
7+
open System.Text.RegularExpressions
8+
9+
open Ionide.LanguageServerProtocol
10+
open Ionide.LanguageServerProtocol.Types
11+
open Microsoft.Build.Construction
12+
open Microsoft.Build.Exceptions
13+
open Microsoft.Build.Locator
14+
open Microsoft.CodeAnalysis
15+
open Microsoft.CodeAnalysis.MSBuild
16+
open Microsoft.CodeAnalysis.Text
17+
open Microsoft.Extensions.Logging
18+
19+
open CSharpLanguageServer
20+
open CSharpLanguageServer.Lsp
21+
open CSharpLanguageServer.Logging
22+
open CSharpLanguageServer.Util
23+
open CSharpLanguageServer.Roslyn.Conversions
24+
open CSharpLanguageServer.Roslyn.WorkspaceServices
25+
open CSharpLanguageServer.Roslyn.Solution
26+
open CSharpLanguageServer.Types
27+
28+
29+
type DecompiledMetadataDocument =
30+
{ Metadata: CSharpMetadataInformation
31+
Document: Document }
32+
33+
34+
/// Codebase wraps roslyn Solution and encapsulates extra metadata
35+
/// that goes along
36+
type Codebase =
37+
{ Solution: Solution
38+
DecompiledMetadata: Map<string, DecompiledMetadataDocument> }
39+
40+
static member LoadWithPathOrOnCwd(lspClient: ILspClient, solutionPathMaybe: string option, cwd: string) = async {
41+
let! solution = async {
42+
match solutionPathMaybe with
43+
| Some solutionPath ->
44+
let rootedSolutionPath =
45+
match Path.IsPathRooted solutionPath with
46+
| true -> solutionPath
47+
| false -> Path.Combine(cwd, solutionPath)
48+
49+
return! solutionTryLoadOnPath lspClient rootedSolutionPath
50+
51+
| None ->
52+
let logMessage: LogMessageParams =
53+
{ Type = MessageType.Info
54+
Message = sprintf "csharp-ls: attempting to find and load solution based on cwd (\"%s\").." cwd }
55+
56+
do! lspClient.WindowLogMessage logMessage
57+
return! solutionFindAndLoadOnDir lspClient cwd
58+
}
59+
60+
return
61+
{ Solution = solution
62+
DecompiledMetadata = Map.empty }
63+
}

src/CSharpLanguageServer/State/ServerState.fs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,10 @@ open CSharpLanguageServer.Logging
1414
open CSharpLanguageServer.Roslyn.Conversions
1515
open CSharpLanguageServer.Roslyn.Solution
1616
open CSharpLanguageServer.Roslyn.Symbol
17+
open CSharpLanguageServer.State.Codebase
1718
open CSharpLanguageServer.Types
1819
open CSharpLanguageServer.Util
1920

20-
type DecompiledMetadataDocument =
21-
{ Metadata: CSharpMetadataInformation
22-
Document: Document }
23-
2421
type ServerRequestMode =
2522
| ReadOnly
2623
| ReadWrite
@@ -56,9 +53,8 @@ and ServerState =
5653
RootPath: string
5754
LspClient: ILspClient option
5855
ClientCapabilities: ClientCapabilities
59-
Solution: Solution option
56+
Codebase: Codebase option
6057
OpenDocs: Map<string, ServerOpenDocInfo>
61-
DecompiledMetadata: Map<string, DecompiledMetadataDocument>
6258
LastRequestId: int
6359
PendingRequests: ServerRequest list
6460
RunningRequests: Map<int, ServerRequest>
@@ -73,9 +69,8 @@ and ServerState =
7369
RootPath = Directory.GetCurrentDirectory()
7470
LspClient = None
7571
ClientCapabilities = emptyClientCapabilities
76-
Solution = None
72+
Codebase = None
7773
OpenDocs = Map.empty
78-
DecompiledMetadata = Map.empty
7974
LastRequestId = 0
8075
PendingRequests = []
8176
RunningRequests = Map.empty

0 commit comments

Comments
 (0)