Skip to content

Commit

Permalink
Merge pull request #145 from razzmatazz/integration-from-rework-viii
Browse files Browse the repository at this point in the history
Integrate refactoring changes (pt. VIII)
  • Loading branch information
razzmatazz authored Apr 11, 2024
2 parents 1a10f6b + b0fbe27 commit d448557
Show file tree
Hide file tree
Showing 24 changed files with 85 additions and 166 deletions.
14 changes: 7 additions & 7 deletions src/CSharpLanguageServer/Handlers/CallHierarchy.fs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ module CallHierarchy =
RegisterOptions = { DocumentSelector = Some defaultDocumentSelector } |> serialize |> Some }


let prepare (wm: ServerRequestScope) (p: CallHierarchyPrepareParams) : AsyncLspResult<CallHierarchyItem[] option> = async {
match! wm.FindSymbol p.TextDocument.Uri p.Position with
let prepare (scope: ServerRequestScope) (p: CallHierarchyPrepareParams) : AsyncLspResult<CallHierarchyItem[] option> = async {
match! scope.FindSymbol p.TextDocument.Uri p.Position with
| Some symbol when isCallableSymbol symbol ->
let! itemList = HierarchyItem.fromSymbol wm.ResolveSymbolLocations symbol
let! itemList = HierarchyItem.fromSymbol scope.ResolveSymbolLocations symbol
return
itemList
|> List.toArray
Expand All @@ -60,7 +60,7 @@ module CallHierarchy =
}

let incomingCalls
(wm: ServerRequestScope)
(scope: ServerRequestScope)
(p: CallHierarchyIncomingCallsParams)
: AsyncLspResult<CallHierarchyIncomingCall[] option> = async {
let toCallHierarchyIncomingCalls (info: SymbolCallerInfo) : CallHierarchyIncomingCall seq =
Expand All @@ -73,10 +73,10 @@ module CallHierarchy =
{ From = HierarchyItem.fromSymbolAndLocation (info.CallingSymbol) (loc |> Location.fromRoslynLocation)
FromRanges = fromRanges })

match! wm.FindSymbol p.Item.Uri p.Item.Range.Start with
match! scope.FindSymbol p.Item.Uri p.Item.Range.Start with
| None -> return None |> success
| Some symbol ->
let! callers = wm.FindCallers symbol
let! callers = scope.FindCallers symbol
// TODO: If we remove info.IsDirect, then we will get lots of false positive. But if we keep it,
// we will miss many callers. Maybe it should have some change in LSP protocol.
return
Expand All @@ -89,7 +89,7 @@ module CallHierarchy =
}

let outgoingCalls
(wm: ServerRequestScope)
(scope: ServerRequestScope)
(p: CallHierarchyOutgoingCallsParams)
: AsyncLspResult<CallHierarchyOutgoingCall[] option> = async {
// TODO: There is no memthod of SymbolFinder which can find all outgoing calls of a specific symbol.
Expand Down
14 changes: 7 additions & 7 deletions src/CSharpLanguageServer/Handlers/CodeAction.fs
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,10 @@ module CodeAction =
ResolveProvider = Some true
DocumentSelector = Some defaultDocumentSelector } |> serialize |> Some }

let handle (wm: ServerRequestScope)
let handle (scope: ServerRequestScope)
(p: CodeActionParams)
: AsyncLspResult<TextDocumentCodeActionResult option> = async {
match wm.GetAnyDocumentForUri p.TextDocument.Uri with
match scope.GetDocument p.TextDocument.Uri with
| None -> return None |> success
| Some doc ->
let! docText = doc.GetTextAsync() |> Async.AwaitTask
Expand All @@ -330,7 +330,7 @@ module CodeAction =
let! roslynCodeActions = getRoslynCodeActions doc textSpan

let clientSupportsCodeActionEditResolveWithEditAndData =
wm.ClientCapabilities
scope.ClientCapabilities
|> Option.bind (fun x -> x.TextDocument)
|> Option.bind (fun x -> x.CodeAction)
|> Option.bind (fun x -> x.ResolveSupport)
Expand Down Expand Up @@ -362,7 +362,7 @@ module CodeAction =
let! maybeLspCa =
roslynCodeActionToResolvedLspCodeAction
doc.Project.Solution
wm.GetDocumentVersion
scope.GetDocumentVersion
doc
ca

Expand All @@ -381,12 +381,12 @@ module CodeAction =
|> success
}

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

match wm.GetAnyDocumentForUri resolutionData.Value.TextDocumentUri with
match scope.GetDocument resolutionData.Value.TextDocumentUri with
| None -> return None |> success
| Some doc ->
let! ct = Async.CancellationToken
Expand All @@ -402,7 +402,7 @@ module CodeAction =
let toResolvedLspCodeAction =
roslynCodeActionToResolvedLspCodeAction
doc.Project.Solution
wm.GetDocumentVersion
scope.GetDocumentVersion
doc

let! maybeLspCodeAction =
Expand Down
4 changes: 2 additions & 2 deletions src/CSharpLanguageServer/Handlers/CodeLens.fs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ module CodeLens =
DocumentSelector = Some defaultDocumentSelector } |> serialize |> Some }

let handle (scope: ServerRequestScope) (p: CodeLensParams): AsyncLspResult<CodeLens[] option> = async {
let docMaybe = scope.GetAnyDocumentForUri p.TextDocument.Uri
let docMaybe = scope.GetDocument p.TextDocument.Uri
match docMaybe with
| None -> return None |> success
| Some doc ->
Expand Down Expand Up @@ -170,7 +170,7 @@ module CodeLens =
|> Option.map (fun t -> t.ToObject<CodeLensData>())
|> Option.defaultValue CodeLensData.Default

let docMaybe = scope.GetAnyDocumentForUri lensData.DocumentUri
let docMaybe = scope.GetDocument lensData.DocumentUri
let doc = docMaybe.Value

let! sourceText = doc.GetTextAsync(ct) |> Async.AwaitTask
Expand Down
2 changes: 1 addition & 1 deletion src/CSharpLanguageServer/Handlers/Completion.fs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ module Completion =
Documentation = description |> Option.map (fun x -> Documentation.String x.Text) }

let handle (scope: ServerRequestScope) (p: Types.CompletionParams): AsyncLspResult<Types.CompletionList option> = async {
let docMaybe = scope.GetUserDocumentForUri p.TextDocument.Uri
let docMaybe = scope.GetUserDocument p.TextDocument.Uri
match docMaybe with
| None -> return None |> success
| Some doc ->
Expand Down
6 changes: 3 additions & 3 deletions src/CSharpLanguageServer/Handlers/Definition.fs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ module Definition =
Method = "textDocument/definition"
RegisterOptions = { DocumentSelector = Some defaultDocumentSelector } |> serialize |> Some }

let handle (wm: ServerRequestScope) (p: TextDocumentPositionParams) : AsyncLspResult<GotoResult option> = async {
match! wm.FindSymbol' p.TextDocument.Uri p.Position with
let handle (scope: ServerRequestScope) (p: TextDocumentPositionParams) : AsyncLspResult<GotoResult option> = async {
match! scope.FindSymbol' p.TextDocument.Uri p.Position with
| None -> return None |> success
| Some (symbol, doc) ->
let! locations = wm.ResolveSymbolLocations symbol (Some doc.Project)
let! locations = scope.ResolveSymbolLocations symbol (Some doc.Project)
return
locations
|> Array.ofList
Expand Down
2 changes: 1 addition & 1 deletion src/CSharpLanguageServer/Handlers/DocumentFormatting.fs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module DocumentFormatting =
RegisterOptions = { DocumentSelector = Some defaultDocumentSelector } |> serialize |> Some }

let handle (scope: ServerRequestScope) (p: DocumentFormattingParams) : AsyncLspResult<TextEdit [] option> = async {
match scope.GetUserDocumentForUri p.TextDocument.Uri with
match scope.GetUserDocument p.TextDocument.Uri with
| None -> return None |> success
| Some doc ->
let options = FormatUtil.getFormattingOptions doc p.Options
Expand Down
4 changes: 2 additions & 2 deletions src/CSharpLanguageServer/Handlers/DocumentHighlight.fs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ module DocumentHighlight =
Kind = Some DocumentHighlightKind.Read })
}

match scope.GetDocumentForUriOfType AnyDocument p.TextDocument.Uri with
match scope.GetDocument p.TextDocument.Uri with
| None -> return None |> success
| Some (doc, docType) ->
| Some doc ->
let! sourceText = doc.GetTextAsync() |> Async.AwaitTask
let position = Position.toRoslynPosition sourceText.Lines p.Position
let! symbol = SymbolFinder.FindSymbolAtPositionAsync(doc, position) |> Async.AwaitTask
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module DocumentOnTypeFormatting =
DocumentSelector = Some defaultDocumentSelector } |> serialize |> Some }

let handle (scope: ServerRequestScope) (p: DocumentOnTypeFormattingParams) : AsyncLspResult<TextEdit[] option> = async {
match scope.GetUserDocumentForUri p.TextDocument.Uri with
match scope.GetUserDocument p.TextDocument.Uri with
| None -> return None |> success
| Some doc ->
let options = FormatUtil.getFormattingOptions doc p.Options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module DocumentRangeFormatting =
RegisterOptions = { DocumentSelector = Some defaultDocumentSelector } |> serialize |> Some }

let handle (scope: ServerRequestScope) (p: DocumentRangeFormattingParams) : AsyncLspResult<TextEdit[] option> = async {
match scope.GetUserDocumentForUri p.TextDocument.Uri with
match scope.GetUserDocument p.TextDocument.Uri with
| None -> return None |> success
| Some doc ->
let options = FormatUtil.getFormattingOptions doc p.Options
Expand Down
2 changes: 1 addition & 1 deletion src/CSharpLanguageServer/Handlers/DocumentSymbol.fs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ module DocumentSymbol =
|> Option.bind (fun cc -> cc.HierarchicalDocumentSymbolSupport)
|> Option.defaultValue false

match scope.GetAnyDocumentForUri p.TextDocument.Uri with
match scope.GetDocument p.TextDocument.Uri with
| None -> return None |> success
| Some doc ->
let! semanticModel = doc.GetSemanticModelAsync() |> Async.AwaitTask
Expand Down
4 changes: 2 additions & 2 deletions src/CSharpLanguageServer/Handlers/Hover.fs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ module Hover =
RegisterOptions = { DocumentSelector = Some defaultDocumentSelector } |> serialize |> Some }

let handle (scope: ServerRequestScope) (p: TextDocumentPositionParams) : AsyncLspResult<Hover option> = async {
match! scope.GetSymbolAtPositionOnAnyDocument p.TextDocument.Uri p.Position with
match! scope.FindSymbol' p.TextDocument.Uri p.Position with
| None -> return None |> success
| Some (symbol, doc, pos) ->
| Some (symbol, doc) ->
let! semanticModel = doc.GetSemanticModelAsync() |> Async.AwaitTask
let content = DocumentationUtil.markdownDocForSymbolWithSignature symbol semanticModel |> markdown
let hover =
Expand Down
8 changes: 4 additions & 4 deletions src/CSharpLanguageServer/Handlers/Implementation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ module Implementation =
Method = "textDocument/implementation"
RegisterOptions = { DocumentSelector = Some defaultDocumentSelector } |> serialize |> Some }

let handle (wm: ServerRequestScope) (p: TextDocumentPositionParams) : AsyncLspResult<GotoResult option> = async {
match! wm.FindSymbol p.TextDocument.Uri p.Position with
let handle (scope: ServerRequestScope) (p: TextDocumentPositionParams) : AsyncLspResult<GotoResult option> = async {
match! scope.FindSymbol p.TextDocument.Uri p.Position with
| None -> return None |> success
| Some symbol ->
let! impls = wm.FindImplementations symbol
let! locations = impls |> Seq.map (flip wm.ResolveSymbolLocations None) |> Async.Parallel
let! impls = scope.FindImplementations symbol
let! locations = impls |> Seq.map (flip scope.ResolveSymbolLocations None) |> Async.Parallel

return
locations
Expand Down
2 changes: 1 addition & 1 deletion src/CSharpLanguageServer/Handlers/InlayHint.fs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ module InlayHint =
DocumentSelector = Some defaultDocumentSelector } |> serialize |> Some }

let handle (scope: ServerRequestScope) (p: InlayHintParams): AsyncLspResult<InlayHint [] option> = async {
match scope.GetUserDocumentForUri p.TextDocument.Uri with
match scope.GetUserDocument p.TextDocument.Uri with
| None -> return None |> success
| Some doc ->
let! semanticModel = doc.GetSemanticModelAsync() |> Async.AwaitTask
Expand Down
9 changes: 4 additions & 5 deletions src/CSharpLanguageServer/Handlers/Rename.fs
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,10 @@ module Rename =
{ PrepareProvider = Some (prepareSupport clientCapabilities)
DocumentSelector = Some defaultDocumentSelector } |> serialize |> Some }

let prepare (getDocumentForUriFromCurrentState: ServerDocumentType -> string -> Async<Document option>)
(_scope: ServerRequestScope)
let prepare (scope: ServerRequestScope)
(p: PrepareRenameParams)
: AsyncLspResult<PrepareRenameResult option> = async {
match! getDocumentForUriFromCurrentState UserDocument p.TextDocument.Uri with
match scope.GetUserDocument p.TextDocument.Uri with
| None -> return None |> success
| Some doc ->
let! docSyntaxTree = doc.GetSyntaxTreeAsync() |> Async.AwaitTask
Expand Down Expand Up @@ -152,9 +151,9 @@ module Rename =
(scope: ServerRequestScope)
(p: RenameParams)
: AsyncLspResult<WorkspaceEdit option> = async {
match! scope.GetSymbolAtPositionOnUserDocument p.TextDocument.Uri p.Position with
match! scope.FindSymbol' p.TextDocument.Uri p.Position with
| None -> return None |> success
| Some (symbol, doc, _) ->
| Some (symbol, doc) ->
let originalSolution = doc.Project.Solution

let! updatedSolution =
Expand Down
2 changes: 1 addition & 1 deletion src/CSharpLanguageServer/Handlers/SemanticTokens.fs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ module SemanticTokens =
(deltaLine, deltaChar, cLen, cToken, cModifiers)

let private getSemanticTokensRange (scope: ServerRequestScope) (uri: string) (range: Range option): AsyncLspResult<SemanticTokens option> = async {
let docMaybe = scope.GetUserDocumentForUri uri
let docMaybe = scope.GetUserDocument uri
match docMaybe with
| None -> return None |> success
| Some doc ->
Expand Down
2 changes: 1 addition & 1 deletion src/CSharpLanguageServer/Handlers/SignatureHelp.fs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ module SignatureHelp =
DocumentSelector = Some defaultDocumentSelector } |> serialize |> Some }

let handle (scope: ServerRequestScope) (p: SignatureHelpParams): AsyncLspResult<SignatureHelp option> = async {
let docMaybe = scope.GetUserDocumentForUri p.TextDocument.Uri
let docMaybe = scope.GetUserDocument p.TextDocument.Uri
match docMaybe with
| None -> return None |> success
| Some doc ->
Expand Down
23 changes: 21 additions & 2 deletions src/CSharpLanguageServer/Handlers/TextDocumentSync.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,31 @@ open Ionide.LanguageServerProtocol.Types
open Microsoft.CodeAnalysis.Text

open CSharpLanguageServer
open CSharpLanguageServer.Conversions
open CSharpLanguageServer.State
open CSharpLanguageServer.State.ServerState
open CSharpLanguageServer.RoslynHelpers

[<RequireQualifiedAccess>]
module TextDocumentSync =
let private applyLspContentChangesOnRoslynSourceText
(changes: TextDocumentContentChangeEvent[])
(initialSourceText: SourceText) =

let applyLspContentChangeOnRoslynSourceText (sourceText: SourceText) (change: TextDocumentContentChangeEvent) =
match change.Range with
| Some changeRange ->
let changeTextSpan =
changeRange |> Range.toLinePositionSpan sourceText.Lines
|> sourceText.Lines.GetTextSpan

TextChange(changeTextSpan, change.Text) |> sourceText.WithChanges

| None -> SourceText.From(change.Text)

changes |> Seq.fold applyLspContentChangeOnRoslynSourceText initialSourceText


let provider (clientCapabilities: ClientCapabilities option) : TextDocumentSyncOptions option =
Some
{ TextDocumentSyncOptions.Default with
Expand Down Expand Up @@ -79,7 +98,7 @@ module TextDocumentSync =
(changeParams: DidChangeTextDocumentParams)
: Async<LspResult<unit>> =
async {
let docMaybe = scope.GetUserDocumentForUri changeParams.TextDocument.Uri
let docMaybe = scope.GetUserDocument changeParams.TextDocument.Uri
match docMaybe with
| Some doc ->
let! ct = Async.CancellationToken
Expand Down Expand Up @@ -119,7 +138,7 @@ module TextDocumentSync =
(saveParams: DidSaveTextDocumentParams)
: Async<LspResult<unit>> =
// we need to add this file to solution if not already
let doc = scope.GetAnyDocumentForUri saveParams.TextDocument.Uri
let doc = scope.GetDocument saveParams.TextDocument.Uri

match doc with
| Some _ ->
Expand Down
6 changes: 3 additions & 3 deletions src/CSharpLanguageServer/Handlers/TypeDefinition.fs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ module TypeDefinition =
Method = "textDocument/typeDefinition"
RegisterOptions = { DocumentSelector = Some defaultDocumentSelector } |> serialize |> Some }

let handle (wm: ServerRequestScope) (p: TextDocumentPositionParams) : AsyncLspResult<GotoResult option> = async {
match! wm.FindSymbol' p.TextDocument.Uri p.Position with
let handle (scope: ServerRequestScope) (p: TextDocumentPositionParams) : AsyncLspResult<GotoResult option> = async {
match! scope.FindSymbol' p.TextDocument.Uri p.Position with
| None -> return None |> success
| Some (symbol, doc) ->
let typeSymbol =
Expand All @@ -47,7 +47,7 @@ module TypeDefinition =
| _ -> []
let! locations =
typeSymbol
|> map (flip wm.ResolveSymbolLocations (Some doc.Project))
|> map (flip scope.ResolveSymbolLocations (Some doc.Project))
|> Async.Parallel
|> map (Seq.collect id >> Seq.toArray)
return
Expand Down
Loading

0 comments on commit d448557

Please sign in to comment.