Skip to content

Commit

Permalink
Server.fs: show "local" symbol name on textDocument/documentSymbol re…
Browse files Browse the repository at this point in the history
…sponse

..similarly like we do with symbol info-on-hover

Related to issue "Sugestion/Request: Signature of symbol in
documentSymbol" (#42)
  • Loading branch information
razzmatazz committed Aug 18, 2022
1 parent 0e61306 commit b2c920c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/CSharpLanguageServer/Documentation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ let markdownDocForSymbol (sym: ISymbol) =
|> (fun ss -> String.Join("\n", ss))

let markdownDocForSymbolWithSignature (sym: ISymbol) (semanticModel: SemanticModel) pos =
let symbolInfo = symbolToLspSymbolInformation true sym (Some semanticModel) (Some pos)
let symbolInfo = symbolToLspSymbolInformation sym (Some semanticModel) (Some pos)

let symAssemblyName =
sym.ContainingAssembly
Expand Down
19 changes: 14 additions & 5 deletions src/CSharpLanguageServer/RoslynHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,12 @@ let formatSymbol (sym: ISymbol)
| false, _, _ -> sym.Name

let symbolToLspSymbolInformation
showAttributes
(symbol: ISymbol)
(semanticModel: SemanticModel option)
(pos: int option)
: Types.SymbolInformation =
let showAttributes = true

let (symbolName, symbolKind) =
match symbol with
| :? ILocalSymbol as ls ->
Expand Down Expand Up @@ -282,7 +283,7 @@ let symbolToLspSymbolInformation
ContainerName = None }


type DocumentSymbolCollector (documentUri, semanticModel: SemanticModel, showAttributes) =
type DocumentSymbolCollector (documentUri, semanticModel: SemanticModel) =
inherit CSharpSyntaxWalker(SyntaxWalkerDepth.Token)

let mutable collectedSymbols: Types.SymbolInformation list = []
Expand All @@ -293,7 +294,13 @@ type DocumentSymbolCollector (documentUri, semanticModel: SemanticModel, showAtt
Range = identifier.GetLocation().GetLineSpan().Span |> lspRangeForRoslynLinePosSpan
}

let rawSymbol = symbolToLspSymbolInformation showAttributes symbol None None
let identifierStartPos = identifier.GetLocation().SourceSpan.Start

let rawSymbol = symbolToLspSymbolInformation
symbol
(Some semanticModel)
(Some identifierStartPos)

let symbol = { rawSymbol with Location = identifierLocation }

collectedSymbols <- symbol :: collectedSymbols
Expand Down Expand Up @@ -453,8 +460,10 @@ let findSymbolsInSolution (solution: Solution)

symbolsFound <- (List.ofSeq symbols) @ symbolsFound

return Seq.map (fun s -> symbolToLspSymbolInformation true s None None) symbolsFound
|> List.ofSeq
let getSymbolInformation s =
symbolToLspSymbolInformation s None None

return symbolsFound |> Seq.map getSymbolInformation |> List.ofSeq
}

let instantiateRoslynProviders<'ProviderType> (isValidProvider: Type -> bool) =
Expand Down
3 changes: 1 addition & 2 deletions src/CSharpLanguageServer/Server.fs
Original file line number Diff line number Diff line change
Expand Up @@ -671,8 +671,7 @@ let setupServerHandlers options (lspClient: LspClient) =
| Some doc ->
let! ct = Async.CancellationToken
let! semanticModel = doc.GetSemanticModelAsync(ct) |> Async.AwaitTask
let showAttributes = false
let collector = DocumentSymbolCollector(p.TextDocument.Uri, semanticModel, showAttributes)
let collector = DocumentSymbolCollector(p.TextDocument.Uri, semanticModel)

let! syntaxTree = doc.GetSyntaxTreeAsync(ct) |> Async.AwaitTask
collector.Visit(syntaxTree.GetRoot())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,4 +552,4 @@ module Client =

return ()
}
|> Async.Start
|> Async.Start

0 comments on commit b2c920c

Please # to comment.