Skip to content

Upgrade to Ionide.LanguageServerProtocol 0.7.0 #221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 27, 2025
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased]
* Upgrade Ionide.LanguageServerProtocol to 0.7.0:
- https://github.com/razzmatazz/csharp-language-server/pull/221
* Reduce startup notifications by using "window/logMessage"
- By @nikolightsaber in https://github.com/razzmatazz/csharp-language-server/pull/217
* Make sure `.editorconfig` settings are respected, add `csharp.applyFormattingOptions` override (defaults to false):
Expand Down
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<PackageVersion Include="DotNet.ReproducibleBuilds" Version="1.2.4" />
<PackageVersion Include="ICSharpCode.Decompiler" Version="8.2.0.7535" />
<PackageVersion Include="Ionide.KeepAChangelog.Tasks" Version="0.1.8" />
<PackageVersion Include="Ionide.LanguageServerProtocol" Version="0.6.0" />
<PackageVersion Include="Ionide.LanguageServerProtocol" Version="0.7.0" />
<PackageVersion Include="Microsoft.Build" Version="$(MSBuildPackageVersion)" />
<PackageVersion Include="Microsoft.Build.Framework" Version="$(MSBuildPackageVersion)" />
<PackageVersion Include="Microsoft.Build.Locator" Version="$(MSBuildLocatorPackageVersion)" />
Expand Down
1 change: 1 addition & 0 deletions src/CSharpLanguageServer/Handlers/CSharpMetadata.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace CSharpLanguageServer.Handlers

open Ionide.LanguageServerProtocol.Types
open Ionide.LanguageServerProtocol.JsonRpc

open CSharpLanguageServer.Types
open CSharpLanguageServer.State
Expand Down
12 changes: 6 additions & 6 deletions src/CSharpLanguageServer/Handlers/CallHierarchy.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ open Microsoft.CodeAnalysis
open Microsoft.CodeAnalysis.FindSymbols
open Ionide.LanguageServerProtocol.Server
open Ionide.LanguageServerProtocol.Types
open Ionide.LanguageServerProtocol.Types.LspResult
open Ionide.LanguageServerProtocol.JsonRpc

open CSharpLanguageServer.Types
open CSharpLanguageServer.State
Expand Down Expand Up @@ -58,8 +58,8 @@ module CallHierarchy =
itemList
|> List.toArray
|> Some
|> success
| _ -> return None |> success
|> LspResult.success
| _ -> return None |> LspResult.success
}

let incomingCalls
Expand All @@ -81,7 +81,7 @@ module CallHierarchy =
FromRanges = fromRanges })

match! context.FindSymbol p.Item.Uri p.Item.Range.Start with
| None -> return None |> success
| None -> return None |> LspResult.success
| Some symbol ->
let! callers = context.FindCallers symbol
// TODO: If we remove info.IsDirect, then we will get lots of false positive. But if we keep it,
Expand All @@ -93,7 +93,7 @@ module CallHierarchy =
|> Seq.distinct
|> Seq.toArray
|> Some
|> success
|> LspResult.success
}

let outgoingCalls
Expand All @@ -102,5 +102,5 @@ module CallHierarchy =
: AsyncLspResult<CallHierarchyOutgoingCall[] option> = async {
// TODO: There is no memthod of SymbolFinder which can find all outgoing calls of a specific symbol.
// Then how can we implement it? Parsing AST manually?
return None |> success
return None |> LspResult.success
}
20 changes: 11 additions & 9 deletions src/CSharpLanguageServer/Handlers/CodeAction.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ open Microsoft.CodeAnalysis.CodeFixes
open Microsoft.CodeAnalysis.Text
open Ionide.LanguageServerProtocol.Server
open Ionide.LanguageServerProtocol.Types
open Ionide.LanguageServerProtocol.Types.LspResult
open Ionide.LanguageServerProtocol.JsonRpc

open CSharpLanguageServer.Logging
open CSharpLanguageServer.Conversions
Expand Down Expand Up @@ -324,7 +324,7 @@ module CodeAction =
(p: CodeActionParams)
: AsyncLspResult<TextDocumentCodeActionResult option> = async {
match context.GetDocument p.TextDocument.Uri with
| None -> return None |> success
| None -> return None |> LspResult.success
| Some doc ->
let! ct = Async.CancellationToken
let! docText = doc.GetTextAsync(ct) |> Async.AwaitTask
Expand Down Expand Up @@ -384,16 +384,17 @@ module CodeAction =
|> Seq.map U2<Command, CodeAction>.C2
|> Array.ofSeq
|> Some
|> success
|> LspResult.success
}

let resolve (context: ServerRequestContext) (p: CodeAction) : AsyncLspResult<CodeAction option> = async {
let resolve (context: ServerRequestContext) (p: CodeAction) : AsyncLspResult<CodeAction> = async {
let resolutionData =
p.Data
|> Option.map deserialize<CSharpCodeActionResolutionData>

match context.GetDocument resolutionData.Value.TextDocumentUri with
| None -> return None |> success
| None ->
return raise (Exception(sprintf "no document for uri %s" resolutionData.Value.TextDocumentUri))
| Some doc ->
let! ct = Async.CancellationToken
let! docText = doc.GetTextAsync(ct) |> Async.AwaitTask
Expand All @@ -412,7 +413,7 @@ module CodeAction =
doc
ct

let! maybeLspCodeAction =
let! lspCodeAction =
match selectedCodeAction with
| Some ca -> async {
let! resolvedCA = toResolvedLspCodeAction ca
Expand All @@ -423,9 +424,10 @@ module CodeAction =
>> Log.addContext "action" (string ca)
)

return resolvedCA
return resolvedCA.Value
}
| None -> async { return None }
| None ->
raise (Exception("no CodeAction resolved"))

return maybeLspCodeAction |> success
return lspCodeAction |> LspResult.success
}
15 changes: 8 additions & 7 deletions src/CSharpLanguageServer/Handlers/CodeLens.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ open Microsoft.CodeAnalysis.CSharp.Syntax
open Microsoft.CodeAnalysis.Text
open Ionide.LanguageServerProtocol.Server
open Ionide.LanguageServerProtocol.Types
open Ionide.LanguageServerProtocol.Types.LspResult
open Newtonsoft.Json.Linq
open Ionide.LanguageServerProtocol.JsonRpc

open CSharpLanguageServer.State
open CSharpLanguageServer.Conversions
Expand Down Expand Up @@ -124,7 +123,8 @@ module CodeLens =
let handle (context: ServerRequestContext) (p: CodeLensParams): AsyncLspResult<CodeLens[] option> = async {
let docMaybe = context.GetDocument p.TextDocument.Uri
match docMaybe with
| None -> return None |> success
| None ->
return None |> LspResult.success
| Some doc ->
let! ct = Async.CancellationToken
let! semanticModel = doc.GetSemanticModelAsync(ct) |> Async.AwaitTask
Expand All @@ -144,11 +144,11 @@ module CodeLens =

{ Range = nameSpan |> Range.fromTextSpan docText.Lines
Command = None
Data = lensData |> JToken.FromObject |> Some }
Data = lensData |> serialize |> Some }

let codeLens = collector.GetSymbols() |> Seq.map makeCodeLens

return codeLens |> Array.ofSeq |> Some |> success
return codeLens |> Array.ofSeq |> Some |> LspResult.success
}

let resolve (context: ServerRequestContext)
Expand All @@ -160,7 +160,8 @@ module CodeLens =
|> Option.defaultValue CodeLensData.Default

match! context.FindSymbol lensData.DocumentUri lensData.Position with
| None -> return p |> success
| None ->
return p |> LspResult.success
| Some symbol ->
let! locations = context.FindReferences symbol false
// FIXME: refNum is wrong. There are lots of false positive even if we distinct locations by
Expand All @@ -183,5 +184,5 @@ module CodeLens =
Command = "textDocument/references"
Arguments = Some [| arg |> serialize |] }

return { p with Command = Some command } |> success
return { p with Command = Some command } |> LspResult.success
}
1 change: 1 addition & 0 deletions src/CSharpLanguageServer/Handlers/Color.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace CSharpLanguageServer.Handlers

open Ionide.LanguageServerProtocol.Types
open Ionide.LanguageServerProtocol.JsonRpc

open CSharpLanguageServer.State

Expand Down
20 changes: 12 additions & 8 deletions src/CSharpLanguageServer/Handlers/Completion.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ open System.Reflection

open Ionide.LanguageServerProtocol.Server
open Ionide.LanguageServerProtocol.Types
open Ionide.LanguageServerProtocol.Types.LspResult
open Ionide.LanguageServerProtocol.JsonRpc

open CSharpLanguageServer
open CSharpLanguageServer.State
Expand All @@ -16,7 +16,7 @@ open CSharpLanguageServer.Logging

[<RequireQualifiedAccess>]
module Completion =
let private logger = LogProvider.getLoggerByName "Completion"
let private _logger = LogProvider.getLoggerByName "Completion"

let emptyRoslynOptionSet: Microsoft.CodeAnalysis.Options.OptionSet =
let osType = typeof<Microsoft.CodeAnalysis.Options.OptionSet>
Expand Down Expand Up @@ -134,9 +134,10 @@ module Completion =

let private cache = new LruCache<(Microsoft.CodeAnalysis.Document * Microsoft.CodeAnalysis.Completion.CompletionList)>(5)

let handle (context: ServerRequestContext) (p: CompletionParams) : AsyncLspResult<Ionide.LanguageServerProtocol.Types.CompletionList option> = async {
let handle (context: ServerRequestContext) (p: CompletionParams) : Async<LspResult<U2<CompletionItem array, CompletionList> option>> = async {
match context.GetDocument p.TextDocument.Uri with
| None -> return None |> success
| None ->
return None |> LspResult.success
| Some doc ->
let! ct = Async.CancellationToken
let! sourceText = doc.GetTextAsync(ct) |> Async.AwaitTask
Expand All @@ -162,7 +163,7 @@ module Completion =
completionService.GetCompletionsAsync(doc, position, completionOptions, completionTrigger, ct)
|> Async.map Option.ofObj
else
async.Return Option.None
async.Return None

return
completions
Expand All @@ -175,7 +176,8 @@ module Completion =
{ IsIncomplete = true
Items = items
ItemDefaults = None })
|> success
|> Option.map U2.C2
|> LspResult.success
}

let resolve (_context: ServerRequestContext) (item: CompletionItem) : AsyncLspResult<CompletionItem> = async {
Expand All @@ -188,7 +190,6 @@ module Completion =
|> Seq.tryFind (fun x -> x.DisplayText = item.Label && (item.SortText.IsNone || x.SortText = item.SortText.Value))
|> Option.map (fun x -> (doc, x)))
with
| None -> return item |> success
| Some (doc, cachedItem) ->
let completionService = Microsoft.CodeAnalysis.Completion.CompletionService.GetService(doc)
let! ct = Async.CancellationToken
Expand All @@ -198,5 +199,8 @@ module Completion =
|> Async.map Option.ofObj
// TODO: make the doc as a markdown string instead of a plain text
let itemDocumentation = description |> Option.map Documentation.fromCompletionDescription
return { item with Documentation = itemDocumentation |> Option.map U2.C2 } |> success
return { item with Documentation = itemDocumentation |> Option.map U2.C2 }
|> LspResult.success
| None ->
return item |> LspResult.success
}
5 changes: 3 additions & 2 deletions src/CSharpLanguageServer/Handlers/Declaration.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace CSharpLanguageServer.Handlers

open Ionide.LanguageServerProtocol.Types
open Ionide.LanguageServerProtocol.JsonRpc

open CSharpLanguageServer.State

Expand All @@ -10,5 +11,5 @@ module Declaration =

let registration (_cc: ClientCapabilities) : Registration option = None

let handle (_context: ServerRequestContext) (_p: TextDocumentPositionParams) : AsyncLspResult<Declaration option> =
LspResult.notImplemented<Declaration option> |> async.Return
let handle (_context: ServerRequestContext) (_p: DeclarationParams) : AsyncLspResult<U2<Declaration,DeclarationLink array> option> =
LspResult.notImplemented<U2<Declaration,DeclarationLink array> option> |> async.Return
12 changes: 7 additions & 5 deletions src/CSharpLanguageServer/Handlers/Definition.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ open System

open Ionide.LanguageServerProtocol.Server
open Ionide.LanguageServerProtocol.Types
open Ionide.LanguageServerProtocol.Types.LspResult
open Ionide.LanguageServerProtocol.JsonRpc

open CSharpLanguageServer.State
open CSharpLanguageServer.Types
Expand Down Expand Up @@ -34,15 +34,17 @@ module Definition =
Method = "textDocument/definition"
RegisterOptions = registerOptions |> serialize |> Some }

let handle (context: ServerRequestContext) (p: TextDocumentPositionParams) : AsyncLspResult<Declaration option> = async {
let handle (context: ServerRequestContext) (p: DefinitionParams) : Async<LspResult<U2<Definition, DefinitionLink array> option>> = async {
match! context.FindSymbol' p.TextDocument.Uri p.Position with
| None -> return None |> success
| None ->
return None |> LspResult.success
| Some (symbol, doc) ->
let! locations = context.ResolveSymbolLocations symbol (Some doc.Project)
return
locations
|> Array.ofList
|> Declaration.C2
|> Definition.C2
|> U2.C1
|> Some
|> success
|> LspResult.success
}
1 change: 1 addition & 0 deletions src/CSharpLanguageServer/Handlers/Diagnostic.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ open System

open Ionide.LanguageServerProtocol.Server
open Ionide.LanguageServerProtocol.Types
open Ionide.LanguageServerProtocol.JsonRpc

open CSharpLanguageServer.Conversions
open CSharpLanguageServer.State
Expand Down
6 changes: 3 additions & 3 deletions src/CSharpLanguageServer/Handlers/DocumentFormatting.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ open System
open Microsoft.CodeAnalysis.Formatting
open Ionide.LanguageServerProtocol.Server
open Ionide.LanguageServerProtocol.Types
open Ionide.LanguageServerProtocol.Types.LspResult
open Ionide.LanguageServerProtocol.JsonRpc

open CSharpLanguageServer
open CSharpLanguageServer.State
Expand Down Expand Up @@ -38,11 +38,11 @@ module DocumentFormatting =

let handle (context: ServerRequestContext) (p: DocumentFormattingParams) : AsyncLspResult<TextEdit [] option> = async {
match context.GetUserDocument p.TextDocument.Uri with
| None -> return None |> success
| None -> return None |> LspResult.success
| Some doc ->
let! ct = Async.CancellationToken
let! options = FormatUtil.getFormattingOptions context.State.Settings doc p.Options
let! newDoc = Formatter.FormatAsync(doc, options, cancellationToken=ct) |> Async.AwaitTask
let! textEdits = FormatUtil.getChanges newDoc doc
return textEdits |> Some |> success
return textEdits |> Some |> LspResult.success
}
10 changes: 5 additions & 5 deletions src/CSharpLanguageServer/Handlers/DocumentHighlight.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ open Microsoft.CodeAnalysis
open Microsoft.CodeAnalysis.FindSymbols
open Ionide.LanguageServerProtocol.Server
open Ionide.LanguageServerProtocol.Types
open Ionide.LanguageServerProtocol.Types.LspResult
open Ionide.LanguageServerProtocol.JsonRpc

open CSharpLanguageServer.Types
open CSharpLanguageServer.State
Expand Down Expand Up @@ -45,7 +45,7 @@ module DocumentHighlight =
| :? INamespaceSymbol -> false
| _ -> true

let handle (context: ServerRequestContext) (p: TextDocumentPositionParams) : AsyncLspResult<DocumentHighlight[] option> = async {
let handle (context: ServerRequestContext) (p: DocumentHighlightParams) : AsyncLspResult<DocumentHighlight[] option> = async {
let! ct = Async.CancellationToken
let filePath = Uri.toPath p.TextDocument.Uri

Expand Down Expand Up @@ -74,11 +74,11 @@ module DocumentHighlight =
}

match! context.FindSymbol' p.TextDocument.Uri p.Position with
| None -> return None |> success
| None -> return None |> LspResult.success
| Some (symbol, doc) ->
match Option.ofObj symbol with
| Some symbol when shouldHighlight symbol ->
let! highlights = getHighlights symbol doc
return highlights |> Seq.toArray |> Some |> success
| _ -> return None |> success
return highlights |> Seq.toArray |> Some |> LspResult.success
| _ -> return None |> LspResult.success
}
1 change: 1 addition & 0 deletions src/CSharpLanguageServer/Handlers/DocumentLink.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace CSharpLanguageServer.Handlers

open Ionide.LanguageServerProtocol.Types
open Ionide.LanguageServerProtocol.JsonRpc

open CSharpLanguageServer.State

Expand Down
Loading
Loading