Skip to content

Commit ea70656

Browse files
committed
Upgrade to FCS 39 + fix warnings
1 parent 8d4399a commit ea70656

17 files changed

+906
-863
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ node_modules/
66
.idea/
77
build.vsix
88
Scratch.fsx
9-
Scratch.ts
9+
Scratch.ts
10+
fsharp-language-server.sln.DotSettings.user
+84-85
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module FSharpLanguageServer.Conversions
1+
module FSharpLanguageServer.Conversions
22

33
open LSP.Log
44
open FSharp.Compiler
@@ -8,45 +8,44 @@ open System.IO
88
open LSP.Types
99
open FSharp.Data
1010

11-
module Ast = FSharp.Compiler.Ast
12-
1311
/// Convert an F# Compiler Services 'FSharpErrorInfo' to an LSP 'Range'
14-
let private errorAsRange(err: FSharpErrorInfo): Range =
12+
let private errorAsRange(err: FSharpDiagnostic): Range =
1513
{
1614
// Got error "The field, constructor or member 'StartLine' is not defined"
1715
start = {line=err.StartLineAlternate-1; character=err.StartColumn}
1816
``end`` = {line=err.EndLineAlternate-1; character=err.EndColumn}
1917
}
2018

2119
/// Convert an F# `Range.pos` to an LSP `Position`
22-
let private asPosition(p: Range.pos): Position =
20+
let private asPosition(p: Text.pos): Position =
2321
{
2422
line=p.Line-1
2523
character=p.Column
2624
}
2725

2826
/// Convert an F# `Range.range` to an LSP `Range`
29-
let asRange(r: Range.range): Range =
27+
let asRange(r: Text.range): Range =
3028
{
3129
start=asPosition r.Start
3230
``end``=asPosition r.End
3331
}
3432

3533
/// Convert an F# `Range.range` to an LSP `Location`
36-
let private asLocation(l: Range.range): Location =
37-
{
34+
let private asLocation(l: Text.range): Location =
35+
{
3836
uri=Uri("file://" + l.FileName)
39-
range = asRange l
37+
range = asRange l
4038
}
4139

4240
/// Convert an F# Compiler Services 'FSharpErrorSeverity' to an LSP 'DiagnosticSeverity'
43-
let private asDiagnosticSeverity(s: FSharpErrorSeverity): DiagnosticSeverity =
44-
match s with
45-
| FSharpErrorSeverity.Warning -> DiagnosticSeverity.Warning
46-
| FSharpErrorSeverity.Error -> DiagnosticSeverity.Error
41+
let private asDiagnosticSeverity(s: FSharpDiagnosticSeverity): DiagnosticSeverity =
42+
match s with
43+
| FSharpDiagnosticSeverity.Warning -> DiagnosticSeverity.Warning
44+
| FSharpDiagnosticSeverity.Error -> DiagnosticSeverity.Error
45+
| FSharpDiagnosticSeverity.Info -> DiagnosticSeverity.Information
4746

4847
/// Convert an F# Compiler Services 'FSharpErrorInfo' to an LSP 'Diagnostic'
49-
let asDiagnostic(err: FSharpErrorInfo): Diagnostic =
48+
let asDiagnostic(err: FSharpDiagnostic): Diagnostic =
5049
{
5150
range = errorAsRange(err)
5251
severity = Some(asDiagnosticSeverity(err.Severity))
@@ -56,18 +55,18 @@ let asDiagnostic(err: FSharpErrorInfo): Diagnostic =
5655
}
5756

5857
/// Create a Diagnostic
59-
let diagnostic(message: string, range: Range.range, severity: DiagnosticSeverity): Diagnostic =
58+
let diagnostic(message: string, range: Text.range, severity: DiagnosticSeverity): Diagnostic =
6059
{
6160
range = asRange(range)
6261
severity = Some(severity)
63-
code = None
64-
source = None
62+
code = None
63+
source = None
6564
message = message
6665
}
67-
66+
6867
/// Some compiler errors have no location in the file and should be displayed at the top of the file
69-
let private hasNoLocation(err: FSharpErrorInfo): bool =
70-
err.StartLineAlternate-1 = 0 &&
68+
let private hasNoLocation(err: FSharpDiagnostic): bool =
69+
err.StartLineAlternate-1 = 0 &&
7170
err.StartColumn = 0 &&
7271
err.EndLineAlternate-1 = 0 &&
7372
err.EndColumn = 0
@@ -76,60 +75,60 @@ let private hasNoLocation(err: FSharpErrorInfo): bool =
7675
let errorAtTop(message: string): Diagnostic =
7776
{
7877
range = { start = {line=0; character=0}; ``end`` = {line=0; character=1} }
79-
severity = Some(DiagnosticSeverity.Error)
78+
severity = Some(DiagnosticSeverity.Error)
8079
code = None
81-
source = None
80+
source = None
8281
message = message
8382
}
8483

8584
/// Convert a list of F# Compiler Services 'FSharpErrorInfo' to LSP 'Diagnostic'
86-
let asDiagnostics(errors: FSharpErrorInfo seq): Diagnostic list =
87-
[
88-
for err in errors do
89-
if hasNoLocation(err) then
85+
let asDiagnostics(errors: FSharpDiagnostic seq): Diagnostic list =
86+
[
87+
for err in errors do
88+
if hasNoLocation(err) then
9089
yield errorAtTop(sprintf "%s: %s" err.Subcategory err.Message)
9190
else
92-
yield asDiagnostic(err)
91+
yield asDiagnostic(err)
9392
]
9493

9594

9695
/// Convert an F# `FSharpToolTipElement` to an LSP `Hover`
97-
let asHover(FSharpToolTipText tips): Hover =
98-
let elements =
96+
let asHover(FSharpToolTipText tips): Hover =
97+
let elements =
9998
[ for t in tips do
100-
match t with
99+
match t with
101100
| FSharpToolTipElement.CompositionError(e) -> dprintfn "Error rendering tooltip: %s" e
102-
| FSharpToolTipElement.None -> ()
103-
| FSharpToolTipElement.Group(elements) ->
101+
| FSharpToolTipElement.None -> ()
102+
| FSharpToolTipElement.Group(elements) ->
104103
yield! elements ]
105-
let contents =
106-
match elements with
104+
let contents =
105+
match elements with
107106
| [] -> []
108-
| [one] ->
109-
[ yield HighlightedString(one.MainDescription, "fsharp")
110-
match TipFormatter.docComment(one.XmlDoc) with
107+
| [one] ->
108+
[ yield HighlightedString(one.MainDescription, "fsharp")
109+
match TipFormatter.docComment(one.XmlDoc) with
111110
| None -> ()
112111
| Some(markdown) -> yield PlainString(markdown + "\n\n")
113-
match one.Remarks with
114-
| None | Some("") -> ()
115-
| Some(remarks) ->
112+
match one.Remarks with
113+
| None | Some("") -> ()
114+
| Some(remarks) ->
116115
yield PlainString("*" + remarks + "*\n\n") ]
117-
| many ->
116+
| many ->
118117
let last = List.last(many)
119-
[ for e in many do
118+
[ for e in many do
120119
yield HighlightedString(e.MainDescription, "fsharp")
121-
match TipFormatter.docSummaryOnly(last.XmlDoc) with
120+
match TipFormatter.docSummaryOnly(last.XmlDoc) with
122121
| None -> ()
123122
| Some(markdown) -> yield PlainString(markdown)
124-
match last.Remarks with
125-
| None | Some("") -> ()
126-
| Some(remarks) ->
123+
match last.Remarks with
124+
| None | Some("") -> ()
125+
| Some(remarks) ->
127126
yield PlainString("*" + remarks + "*\n\n") ]
128127
{contents=contents; range=None}
129128

130129
/// Convert an F# `FSharpGlyph` to an LSP `CompletionItemKind`
131-
let private asCompletionItemKind(k: FSharpGlyph): CompletionItemKind =
132-
match k with
130+
let private asCompletionItemKind(k: FSharpGlyph): CompletionItemKind =
131+
match k with
133132
| FSharpGlyph.Class -> CompletionItemKind.Class
134133
| FSharpGlyph.Constant -> CompletionItemKind.Constant
135134
| FSharpGlyph.Delegate -> CompletionItemKind.Property // ?
@@ -153,9 +152,9 @@ let private asCompletionItemKind(k: FSharpGlyph): CompletionItemKind =
153152
| FSharpGlyph.Error -> CompletionItemKind.Class // ?
154153

155154
/// Convert an F# `FSharpDeclarationListItem` to an LSP `CompletionItem`
156-
let private asCompletionItem(i: FSharpDeclarationListItem): CompletionItem =
157-
{ defaultCompletionItem with
158-
label = i.Name
155+
let private asCompletionItem(i: FSharpDeclarationListItem): CompletionItem =
156+
{ defaultCompletionItem with
157+
label = i.Name
159158
insertText = Some(i.NameInCode)
160159
kind = Some(asCompletionItemKind(i.Glyph))
161160
detail = Some(i.FullName)
@@ -165,50 +164,50 @@ let private asCompletionItem(i: FSharpDeclarationListItem): CompletionItem =
165164

166165
/// Convert an F# `FSharpDeclarationListInfo` to an LSP `CompletionList`
167166
/// Used in rendering autocomplete lists
168-
let asCompletionList(ds: FSharpDeclarationListInfo): CompletionList =
167+
let asCompletionList(ds: FSharpDeclarationListInfo): CompletionList =
169168
let items = [for i in ds.Items do yield asCompletionItem(i)]
170169
{isIncomplete=List.isEmpty(items); items=items}
171170

172171
/// Convert an F# `FSharpMethodGroupItemParameter` to an LSP `ParameterInformation`
173-
let private asParameterInformation(p: FSharpMethodGroupItemParameter): ParameterInformation =
172+
let private asParameterInformation(p: FSharpMethodGroupItemParameter): ParameterInformation =
174173
{
175174
label = p.ParameterName
176175
documentation = Some p.Display
177176
}
178177

179178
/// Convert an F# method name + `FSharpMethodGroupItem` to an LSP `SignatureInformation`
180179
/// Used in providing signature help after autocompleting
181-
let asSignatureInformation(methodName: string, s: FSharpMethodGroupItem): SignatureInformation =
182-
let doc = match s.Description with
183-
| FSharpToolTipText [FSharpToolTipElement.Group [tip]] -> Some tip.MainDescription
184-
| _ ->
185-
dprintfn "Can't render documentation %A" s.Description
186-
None
180+
let asSignatureInformation(methodName: string, s: FSharpMethodGroupItem): SignatureInformation =
181+
let doc = match s.Description with
182+
| FSharpToolTipText [FSharpToolTipElement.Group [tip]] -> Some tip.MainDescription
183+
| _ ->
184+
dprintfn "Can't render documentation %A" s.Description
185+
None
187186
let parameterName(p: FSharpMethodGroupItemParameter) = p.ParameterName
188187
let parameterNames = Array.map parameterName s.Parameters
189188
{
190-
label = sprintf "%s(%s)" methodName (String.concat ", " parameterNames)
191-
documentation = doc
189+
label = sprintf "%s(%s)" methodName (String.concat ", " parameterNames)
190+
documentation = doc
192191
parameters = Array.map asParameterInformation s.Parameters |> List.ofArray
193192
}
194193

195194
/// Get the lcation where `s` was declared
196-
let declarationLocation(s: FSharpSymbol): Location option =
197-
match s.DeclarationLocation with
198-
| None ->
199-
dprintfn "Symbol %s has no declaration" s.FullName
200-
None
195+
let declarationLocation(s: FSharpSymbol): Location option =
196+
match s.DeclarationLocation with
197+
| None ->
198+
dprintfn "Symbol %s has no declaration" s.FullName
199+
None
201200
| Some l ->
202201
Some(asLocation(l))
203202

204203
/// Get the location where `s` was used
205-
let useLocation(s: FSharpSymbolUse): Location =
204+
let useLocation(s: FSharpSymbolUse): Location =
206205
asLocation(s.RangeAlternate)
207206

208207
/// Convert an F# `FSharpNavigationDeclarationItemKind` to an LSP `SymbolKind`
209208
/// `FSharpNavigationDeclarationItemKind` is the level of symbol-type information you get when parsing without typechecking
210-
let private asSymbolKind(k: FSharpNavigationDeclarationItemKind): SymbolKind =
211-
match k with
209+
let private asSymbolKind(k: FSharpNavigationDeclarationItemKind): SymbolKind =
210+
match k with
212211
| NamespaceDecl -> SymbolKind.Namespace
213212
| ModuleFileDecl -> SymbolKind.Module
214213
| ExnDecl -> SymbolKind.Class
@@ -222,17 +221,17 @@ let private asSymbolKind(k: FSharpNavigationDeclarationItemKind): SymbolKind =
222221
/// Convert an F# `NavigationDeclarationItem` to an LSP `SymbolInformation`
223222
/// `NavigationDeclarationItem` is the parsed AST representation of a symbol without typechecking
224223
/// `container` is present when `d` is part of a module or type
225-
let asSymbolInformation(d: NavigationDeclarationItem, container: NavigationDeclarationItem option): SymbolInformation =
226-
let declarationName(d: NavigationDeclarationItem) = d.Name
224+
let asSymbolInformation(d: NavigationItem, container: NavigationItem option): SymbolInformation =
225+
let declarationName(d: NavigationItem) = d.Name
227226
{
228-
name=d.Name
229-
kind=asSymbolKind d.Kind
230-
location=asLocation d.Range
227+
name=d.Name
228+
kind=asSymbolKind d.Kind
229+
location=asLocation d.Range
231230
containerName=Option.map declarationName container
232231
}
233232

234233
/// Convert symbols declared in an .fsi file to a CodeLens that helps the user navigate to the definition
235-
let asGoToImplementation(name: string list, file: FileInfo, range: Range.range): CodeLens =
234+
let asGoToImplementation(name: string list, file: FileInfo, range: Text.range): CodeLens =
236235
let jsonFile = JsonValue.String(file.FullName)
237236
let jsonName = JsonValue.Array([|for i in name do yield JsonValue.String(i)|])
238237
{
@@ -241,13 +240,13 @@ let asGoToImplementation(name: string list, file: FileInfo, range: Range.range):
241240
data=JsonValue.Array([|jsonFile; jsonName|])
242241
}
243242

244-
let goToImplementationData(goTo: CodeLens) =
245-
match goTo.data with
246-
| JsonValue.Array([|JsonValue.String(file); JsonValue.Array(jsonNames)|]) ->
243+
let goToImplementationData(goTo: CodeLens) =
244+
match goTo.data with
245+
| JsonValue.Array([|JsonValue.String(file); JsonValue.Array(jsonNames)|]) ->
247246
FileInfo(file), [for JsonValue.String(j) in jsonNames do yield j ]
248247

249-
let resolveGoToImplementation(unresolved: CodeLens, file: FileInfo, range: Range.range): CodeLens =
250-
let command =
248+
let resolveGoToImplementation(unresolved: CodeLens, file: FileInfo, range: Text.range): CodeLens =
249+
let command =
251250
{
252251
title=sprintf "%s(%d)" file.Name range.StartLine
253252
command="fsharp.command.goto"
@@ -261,8 +260,8 @@ let resolveGoToImplementation(unresolved: CodeLens, file: FileInfo, range: Range
261260
}
262261
{ unresolved with command = Some(command) }
263262

264-
let resolveMissingGoToImplementation(unresolved: CodeLens, file: FileInfo): CodeLens =
265-
let command =
263+
let resolveMissingGoToImplementation(unresolved: CodeLens, file: FileInfo): CodeLens =
264+
let command =
266265
{
267266
title="Not Found"
268267
command="fsharp.command.goto"
@@ -276,7 +275,7 @@ let resolveMissingGoToImplementation(unresolved: CodeLens, file: FileInfo): Code
276275
}
277276
{ unresolved with command = Some(command) }
278277

279-
let asRunTest(fsproj: FileInfo, fullyQualifiedName: string list, test: Ast.SynBinding): CodeLens =
278+
let asRunTest(fsproj: FileInfo, fullyQualifiedName: string list, test: SyntaxTree.SynBinding): CodeLens =
280279
{
281280
range=asRange(test.RangeOfBindingSansRhs)
282281
command=Some({ title="Run Test"
@@ -285,11 +284,11 @@ let asRunTest(fsproj: FileInfo, fullyQualifiedName: string list, test: Ast.SynBi
285284
data=JsonValue.Null
286285
}
287286

288-
let asDebugTest(fsproj: FileInfo, fullyQualifiedName: string list, test: Ast.SynBinding): CodeLens =
287+
let asDebugTest(fsproj: FileInfo, fullyQualifiedName: string list, test: SyntaxTree.SynBinding): CodeLens =
289288
{
290289
range=asRange(test.RangeOfBindingSansRhs)
291290
command=Some({ title="Debug Test"
292291
command="fsharp.command.test.debug"
293292
arguments=[JsonValue.String(fsproj.FullName); JsonValue.String(String.concat "." fullyQualifiedName)] })
294293
data=JsonValue.Null
295-
}
294+
}

src/FSharpLanguageServer/FSharpLanguageServer.fsproj

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>netcoreapp3.0</TargetFramework>
5+
<TargetFramework>net5.0</TargetFramework>
66
<RuntimeIdentifiers>win10-x64;osx.10.11-x64;linux-x64</RuntimeIdentifiers>
77
</PropertyGroup>
88

99
<ItemGroup>
1010
<Compile Include="ProgressBar.fs" />
1111
<Compile Include="TipFormatter.fs" />
12+
<Compile Include="SyntaxTreeOps.fs" />
1213
<Compile Include="Navigation.fs" />
1314
<Compile Include="Conversions.fs" />
1415
<Compile Include="ProjectManager.fs" />
@@ -18,7 +19,7 @@
1819
</ItemGroup>
1920

2021
<ItemGroup>
21-
<PackageReference Include="FSharp.Compiler.Service" Version="34.1.1" />
22+
<PackageReference Include="FSharp.Compiler.Service" Version="39.0.0" />
2223
<PackageReference Include="HtmlAgilityPack" Version="1.8.4" />
2324
</ItemGroup>
2425

0 commit comments

Comments
 (0)