Skip to content

Commit 42c7af7

Browse files
brettfobaronfel
authored andcommitted
add framework for LSP support (#6907)
1 parent fe2973e commit 42c7af7

File tree

16 files changed

+299
-1
lines changed

16 files changed

+299
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ tests/fsharpqa/Source/*FSharpQA_Failures.env
183183
tests/fsharpqa/Source/*FSharpQA_Failures.lst
184184
*.csproj.user
185185
*.fsproj.user
186+
*.vbproj.user
186187
*.sln.DotSettings.user
187188
*.log
188189
*.jrs

eng/Build.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,15 @@ try {
270270

271271
if ($testDesktop) {
272272
TestUsingNUnit -testProject "$RepoRoot\tests\FSharp.Compiler.UnitTests\FSharp.Compiler.UnitTests.fsproj" -targetFramework $desktopTargetFramework
273+
TestUsingNUnit -testProject "$RepoRoot\tests\FSharp.Compiler.LanguageServer.UnitTests\FSharp.Compiler.LanguageServer.UnitTests.fsproj" -targetFramework $desktopTargetFramework
273274
TestUsingNUnit -testProject "$RepoRoot\tests\FSharp.Build.UnitTests\FSharp.Build.UnitTests.fsproj" -targetFramework $desktopTargetFramework
274275
TestUsingNUnit -testProject "$RepoRoot\tests\FSharp.Core.UnitTests\FSharp.Core.UnitTests.fsproj" -targetFramework $desktopTargetFramework
275276
TestUsingNUnit -testProject "$RepoRoot\tests\fsharp\FSharpSuite.Tests.fsproj" -targetFramework $desktopTargetFramework
276277
}
277278

278279
if ($testCoreClr) {
279280
TestUsingNUnit -testProject "$RepoRoot\tests\FSharp.Compiler.UnitTests\FSharp.Compiler.UnitTests.fsproj" -targetFramework $coreclrTargetFramework
281+
TestUsingNUnit -testProject "$RepoRoot\tests\FSharp.Compiler.LanguageServer.UnitTests\FSharp.Compiler.LanguageServer.UnitTests.fsproj" -targetFramework $coreclrTargetFramework
280282
TestUsingNUnit -testProject "$RepoRoot\tests\FSharp.Build.UnitTests\FSharp.Build.UnitTests.fsproj" -targetFramework $coreclrTargetFramework
281283
TestUsingNUnit -testProject "$RepoRoot\tests\FSharp.Core.UnitTests\FSharp.Core.UnitTests.fsproj" -targetFramework $coreclrTargetFramework
282284
TestUsingNUnit -testProject "$RepoRoot\tests\fsharp\FSharpSuite.Tests.fsproj" -targetFramework $coreclrTargetFramework

eng/Versions.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,5 +189,6 @@
189189
<NunitXmlTestLoggerVersion>2.1.36</NunitXmlTestLoggerVersion>
190190
<RoslynToolsSignToolVersion>1.0.0-beta2-dev3</RoslynToolsSignToolVersion>
191191
<StrawberryPerl64Version>5.22.2.1</StrawberryPerl64Version>
192+
<StreamJsonRpcVersion>2.0.187</StreamJsonRpcVersion>
192193
</PropertyGroup>
193194
</Project>

eng/build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ BuildSolution
245245
if [[ "$test_core_clr" == true ]]; then
246246
coreclrtestframework=netcoreapp2.1
247247
TestUsingNUnit --testproject "$repo_root/tests/FSharp.Compiler.UnitTests/FSharp.Compiler.UnitTests.fsproj" --targetframework $coreclrtestframework
248+
TestUsingNUnit --testproject "$repo_root/tests/FSharp.Compiler.LanguageServer.UnitTests/FSharp.Compiler.LanguageServer.UnitTests.fsproj" --targetframework $coreclrtestframework
248249
TestUsingNUnit --testproject "$repo_root/tests/FSharp.Build.UnitTests/FSharp.Build.UnitTests.fsproj" --targetframework $coreclrtestframework
249250
TestUsingNUnit --testproject "$repo_root/tests/FSharp.Core.UnitTests/FSharp.Core.UnitTests.fsproj" --targetframework $coreclrtestframework
250251
fi

fcs/FSharp.Compiler.Service/FSharp.Compiler.Service.fsproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
<PropertyGroup>
33
<FSharpSourcesRoot>$(MSBuildProjectDirectory)\..\..\src</FSharpSourcesRoot>
44
</PropertyGroup>
5-
<Project Sdk="Microsoft.NET.Sdk">
65
<Import Project="..\netfx.props" />
76
<Import Project="..\..\src\buildtools\buildtools.targets" />
87
<PropertyGroup>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project>
2+
3+
<PropertyGroup>
4+
<UseFSharpProductVersion>true</UseFSharpProductVersion>
5+
</PropertyGroup>
6+
7+
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />
8+
9+
</Project>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<!-- Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. -->
2+
<Project Sdk="Microsoft.NET.Sdk">
3+
4+
<PropertyGroup>
5+
<OutputType>Exe</OutputType>
6+
<TargetExt>.exe</TargetExt>
7+
<TargetFrameworks>net472;netcoreapp2.1</TargetFrameworks>
8+
<TargetFrameworks Condition="'$(OS)' == 'Unix'">netcoreapp2.1</TargetFrameworks>
9+
<IsPackable>true</IsPackable>
10+
<PackageDescription>Implements the Language Server Protocol (LSP) for F#.</PackageDescription>
11+
</PropertyGroup>
12+
13+
<ItemGroup>
14+
<Compile Include="State.fs" />
15+
<Compile Include="LspTypes.fs" />
16+
<Compile Include="TextDocument.fs" />
17+
<Compile Include="Methods.fs" />
18+
<Compile Include="Server.fs" />
19+
<Compile Include="Program.fs" />
20+
</ItemGroup>
21+
22+
<ItemGroup>
23+
<ProjectReference Include="$(MSBuildThisFileDirectory)..\FSharp.Compiler.Private\FSharp.Compiler.Private.fsproj" />
24+
<ProjectReference Include="$(MSBuildThisFileDirectory)..\FSharp.Core\FSharp.Core.fsproj" />
25+
</ItemGroup>
26+
27+
<ItemGroup>
28+
<PackageReference Include="StreamJsonRpc" Version="$(StreamJsonRpcVersion)" />
29+
</ItemGroup>
30+
31+
</Project>
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
2+
3+
namespace FSharp.Compiler.LanguageServer
4+
5+
// Interfaces as defined at https://microsoft.github.io/language-server-protocol/specification. The properties on these
6+
// types are camlCased to match the underlying JSON properties to avoid attributes on every field:
7+
// [<JsonProperty("camlCased")>]
8+
9+
/// Represents a zero-based line and column of a text document.
10+
type Position =
11+
{ line: int
12+
character: int }
13+
14+
type Range =
15+
{ start: Position
16+
``end``: Position }
17+
18+
type DocumentUri = string
19+
20+
type Location =
21+
{ uri: DocumentUri
22+
range: Range }
23+
24+
type DiagnosticRelatedInformation =
25+
{ location: Location
26+
message: string }
27+
28+
type Diagnostic =
29+
{ range: Range
30+
severity: int
31+
code: string
32+
source: string // "F#"
33+
message: string
34+
relatedInformation: DiagnosticRelatedInformation[] }
35+
static member Error = 1
36+
static member Warning = 2
37+
static member Information = 3
38+
static member Hint = 4
39+
40+
type PublishDiagnosticsParams =
41+
{ uri: DocumentUri
42+
diagnostics: Diagnostic[] }
43+
44+
type InitializeParams = string // TODO:
45+
46+
// Note, this type has many more optional values that can be expanded as support is added.
47+
type ServerCapabilities =
48+
{ hoverProvider: bool }
49+
static member DefaultCapabilities() =
50+
{ ServerCapabilities.hoverProvider = true }
51+
52+
type InitializeResult =
53+
{ capabilities: ServerCapabilities }
54+
55+
type MarkupKind =
56+
| PlainText
57+
| Markdown
58+
59+
type MarkupContent =
60+
{ kind: MarkupKind
61+
value: string }
62+
63+
type Hover =
64+
{ contents: MarkupContent
65+
range: Range option }
66+
67+
type TextDocumentIdentifier =
68+
{ uri: DocumentUri }
69+
70+
type TextDocumentPositionParams =
71+
{ textDocument: TextDocumentIdentifier
72+
position: Position }
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
2+
3+
namespace FSharp.Compiler.LanguageServer
4+
5+
open StreamJsonRpc
6+
7+
// https://microsoft.github.io/language-server-protocol/specification
8+
type Methods(state: State) =
9+
10+
[<JsonRpcMethod("initialize")>]
11+
member __.Initialize (args: InitializeParams) =
12+
async {
13+
// note, it's important that this method is `async` because unit tests can then properly verify that the
14+
// JSON RPC handling of async methods is correct
15+
return ServerCapabilities.DefaultCapabilities()
16+
} |> Async.StartAsTask
17+
18+
[<JsonRpcMethod("shutdown")>]
19+
member __.Shutdown() = state.DoShutdown()
20+
21+
[<JsonRpcMethod("textDocument/hover")>]
22+
member __.TextDocumentHover (args: TextDocumentPositionParams) = TextDocument.Hover(state, args) |> Async.StartAsTask
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
2+
3+
namespace FSharp.Compiler.LanguageServer
4+
5+
open System
6+
7+
module Program =
8+
9+
[<EntryPoint>]
10+
let main(args: string[]) =
11+
async {
12+
let server = new Server(Console.OpenStandardOutput(), Console.OpenStandardInput())
13+
server.StartListening()
14+
do! server.WaitForExitAsync()
15+
return 0
16+
} |> Async.RunSynchronously

0 commit comments

Comments
 (0)