Skip to content

Commit 1e30ba8

Browse files
committed
basic symbol search
1 parent 413c7e4 commit 1e30ba8

1 file changed

Lines changed: 35 additions & 2 deletions

File tree

glean/lsp/Glean/LSP.hs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ import Data.Path as Path
4646
- make hierarchical
4747
- maybe filter out type parameters?
4848
- call hierarchy
49-
- symbol search
5049
- update index after edits
5150
1. make it possible to re-index on the side and create a new DB,
5251
using a separate glean-server. Need to flush the cache if we
@@ -207,7 +206,7 @@ serverDef glass options = do
207206
-- , handleDidChange
208207
-- , handleDidSave
209208
, handleDidClose
210-
-- , handleWorkspaceSymbol
209+
, handleWorkspaceSymbol
211210
, handleSetTrace
212211
-- , handleCodeAction
213212
-- , handleResolveCodeAction
@@ -316,6 +315,12 @@ handleReferencesRequest =
316315
refs <- findRefs path params._position
317316
res $ Right $ LSP.InL refs
318317

318+
handleWorkspaceSymbol :: LSP.Handlers GleanLspM
319+
handleWorkspaceSymbol = LSP.requestHandler LSP.SMethod_WorkspaceSymbol $ \req res -> do
320+
-- https://hackage.haskell.org/package/lsp-types-1.6.0.0/docs/Language-LSP-Types.html#t:WorkspaceSymbolParams
321+
symbols <- symbolSearch req._params._query
322+
res $ Right . LSP.InL $ symbols
323+
319324
-- -----------------------------------------------------------------------------
320325
-- Glean / Glass stuff
321326

@@ -445,6 +450,34 @@ getDocumentSymbols path = do
445450
, let range = toLspRange sym.symbolX_range
446451
]
447452

453+
symbolSearch ::
454+
Text ->
455+
GleanLspM [LSP.SymbolInformation]
456+
symbolSearch query = do
457+
env <- getGleanLspEnv
458+
cfg :: LspConfig <- LSP.getConfig
459+
let
460+
req = def {
461+
Glass.symbolSearchRequest_name = query,
462+
Glass.symbolSearchRequest_repo_name = Just cfg.repo,
463+
Glass.symbolSearchRequest_options = def {
464+
Glass.symbolSearchOptions_detailedResults = True -- we need kinds
465+
}
466+
}
467+
opts = def
468+
res <- liftIO $ Glass.Handler.searchSymbol env.glass req opts
469+
return [
470+
LSP.SymbolInformation {
471+
_name = sym.symbolDescription_name.qualifiedName_localName.unName,
472+
_kind = maybe LSP.SymbolKind_Function toLspSymbolKind sym.symbolDescription_kind,
473+
_tags = Nothing,
474+
_deprecated = Nothing,
475+
_location = toLspLocation env.wsRoot sym.symbolDescription_sym_location,
476+
_containerName = Nothing
477+
}
478+
| sym <- res.symbolSearchResult_symbolDetails
479+
]
480+
448481
-- -----------------------------------------------------------------------------
449482
-- Data conversion Glass <-> LSP
450483

0 commit comments

Comments
 (0)