Skip to content

Commit

Permalink
Update to lsp-1.2 (haskell#1631)
Browse files Browse the repository at this point in the history
* Update to lsp-1.2

* fix stack

* fix splice plugin tests

* fix tactic plugin tests

* fix some tests

* fix some tests

* fix outline tests

* hlint

* fix func-test
  • Loading branch information
wz1000 authored and berberman committed Apr 4, 2021
1 parent 8eafe56 commit e43ab3f
Show file tree
Hide file tree
Showing 49 changed files with 213 additions and 192 deletions.
2 changes: 1 addition & 1 deletion cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ package *

write-ghc-environment-files: never

index-state: 2021-03-02T21:23:14Z
index-state: 2021-03-29T21:23:14Z

allow-newer:
active:base,
Expand Down
3 changes: 1 addition & 2 deletions ghcide/exe/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import Control.Monad.Extra (unless, when, whenJust)
import qualified Data.Aeson.Encode.Pretty as A
import Data.Default (Default (def))
import Data.List.Extra (upper)
import Data.Maybe (fromMaybe)
import qualified Data.Text as T
import qualified Data.Text.IO as T
import Data.Text.Lazy.Encoding (decodeUtf8)
Expand Down Expand Up @@ -122,7 +121,7 @@ main = do
then Test.plugin
else mempty

,Main.argsIdeOptions = \(fromMaybe def -> config) sessionLoader ->
,Main.argsIdeOptions = \config sessionLoader ->
let defOptions = defaultIdeOptions sessionLoader
in defOptions
{ optShakeProfiling = argsShakeProfiling
Expand Down
8 changes: 4 additions & 4 deletions ghcide/ghcide.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ library
hls-plugin-api ^>= 1.1.0.0,
lens,
hiedb == 0.3.0.1,
lsp-types == 1.1.*,
lsp == 1.1.1.0,
lsp-types == 1.2.*,
lsp == 1.2.*,
mtl,
network-uri,
parallel,
Expand Down Expand Up @@ -339,7 +339,7 @@ test-suite ghcide-tests
hls-plugin-api,
network-uri,
lens,
lsp-test == 0.13.0.0,
lsp-test == 0.14.0.0,
optparse-applicative,
process,
QuickCheck,
Expand Down Expand Up @@ -396,7 +396,7 @@ executable ghcide-bench
extra,
filepath,
ghcide,
lsp-test == 0.13.0.0,
lsp-test == 0.14.0.0,
optparse-applicative,
process,
safe-exceptions,
Expand Down
12 changes: 4 additions & 8 deletions ghcide/src/Development/IDE/Core/Shake.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ module Development.IDE.Core.Shake(
getIdeOptions,
getIdeOptionsIO,
GlobalIdeOptions(..),
getClientConfig,
HLS.getClientConfig,
getPluginConfig,
garbageCollect,
knownTargets,
Expand Down Expand Up @@ -230,14 +230,10 @@ getShakeExtrasRules = do
Just x <- getShakeExtraRules @ShakeExtras
return x

getClientConfig :: LSP.MonadLsp Config m => ShakeExtras -> m Config
getClientConfig ShakeExtras { defaultConfig } =
fromMaybe defaultConfig <$> HLS.getClientConfig

getPluginConfig
:: LSP.MonadLsp Config m => ShakeExtras -> PluginId -> m PluginConfig
getPluginConfig extras plugin = do
config <- getClientConfig extras
:: LSP.MonadLsp Config m => PluginId -> m PluginConfig
getPluginConfig plugin = do
config <- HLS.getClientConfig
return $ HLS.configForPlugin config plugin

-- | Register a function that will be called to get the "stale" result of a rule, possibly from disk
Expand Down
11 changes: 5 additions & 6 deletions ghcide/src/Development/IDE/LSP/LanguageServer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import Data.Aeson (Value)
import Data.Maybe
import qualified Data.Set as Set
import qualified Data.Text as T
import qualified Development.IDE.GHC.Util as Ghcide
import Development.IDE.LSP.Server
import Development.IDE.Session (runWithDb)
import Ide.Types (traceWithSpan)
Expand All @@ -50,11 +49,12 @@ runLanguageServer
-> Handle -- input
-> Handle -- output
-> (FilePath -> IO FilePath) -- ^ Map root paths to the location of the hiedb for the project
-> (IdeState -> Value -> IO (Either T.Text config))
-> config
-> (config -> Value -> Either T.Text config)
-> LSP.Handlers (ServerM config)
-> (LSP.LanguageContextEnv config -> VFSHandle -> Maybe FilePath -> HieDb -> IndexQueue -> IO IdeState)
-> IO ()
runLanguageServer options inH outH getHieDbLoc onConfigurationChange userHandlers getIdeState = do
runLanguageServer options inH outH getHieDbLoc defaultConfig onConfigurationChange userHandlers getIdeState = do

-- These barriers are signaled when the threads reading from these chans exit.
-- This should not happen but if it does, we will make sure that the whole server
Expand Down Expand Up @@ -103,9 +103,8 @@ runLanguageServer options inH outH getHieDbLoc onConfigurationChange userHandler


let serverDefinition = LSP.ServerDefinition
{ LSP.onConfigurationChange = \v -> do
(_chan, ide) <- ask
liftIO $ onConfigurationChange ide v
{ LSP.onConfigurationChange = onConfigurationChange
, LSP.defaultConfig = defaultConfig
, LSP.doInitialize = handleInit exit clearReqId waitForCancel clientMsgChan
, LSP.staticHandlers = asyncHandlers
, LSP.interpretHandler = \(env, st) -> LSP.Iso (LSP.runLspT env . flip runReaderT (clientMsgChan,st)) liftIO
Expand Down
1 change: 0 additions & 1 deletion ghcide/src/Development/IDE/LSP/Notifications.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import qualified Language.LSP.Types.Capabilities as LSP
import Development.IDE.Core.IdeConfiguration
import Development.IDE.Core.Service
import Development.IDE.Core.Shake
import Development.IDE.LSP.Server
import Development.IDE.Types.Location
import Development.IDE.Types.Logger
import Development.IDE.Types.Options
Expand Down
7 changes: 3 additions & 4 deletions ghcide/src/Development/IDE/LSP/Outline.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import qualified Data.Text as T
import Development.IDE.Core.Rules
import Development.IDE.Core.Shake
import Development.IDE.GHC.Compat
import Development.IDE.GHC.Error (realSrcSpanToRange)
import Development.IDE.GHC.Error (realSrcSpanToRange, rangeToRealSrcSpan)
import Development.IDE.Types.Location
import Language.LSP.Server (LspM)
import Language.LSP.Types
Expand Down Expand Up @@ -183,12 +183,10 @@ documentSymbolForImportSummary importSymbols =
mergeRanges xs = Range (minimum $ map _start xs) (maximum $ map _end xs)
importRange = mergeRanges $ map (_range :: DocumentSymbol -> Range) importSymbols
in
Just (defDocumentSymbol empty :: DocumentSymbol)
Just (defDocumentSymbol (rangeToRealSrcSpan "" importRange))
{ _name = "imports"
, _kind = SkModule
, _children = Just (List importSymbols)
, _range = importRange
, _selectionRange = importRange
}

documentSymbolForImport :: Located (ImportDecl GhcPs) -> Maybe DocumentSymbol
Expand All @@ -213,6 +211,7 @@ defDocumentSymbol l = DocumentSymbol { .. } where
_range = realSrcSpanToRange l
_selectionRange = realSrcSpanToRange l
_children = Nothing
_tags = Nothing

showRdrName :: RdrName -> Text
showRdrName = pprText
Expand Down
10 changes: 5 additions & 5 deletions ghcide/src/Development/IDE/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ data Arguments = Arguments
, argsHlsPlugins :: IdePlugins IdeState
, argsGhcidePlugin :: Plugin Config -- ^ Deprecated
, argsSessionLoadingOptions :: SessionLoadingOptions
, argsIdeOptions :: Maybe Config -> Action IdeGhcSession -> IdeOptions
, argsIdeOptions :: Config -> Action IdeGhcSession -> IdeOptions
, argsLspOptions :: LSP.Options
, argsDefaultHlsConfig :: Config
, argsGetHieDbLoc :: FilePath -> IO FilePath -- ^ Map project roots to the location of the hiedb for the project
Expand Down Expand Up @@ -142,11 +142,11 @@ defaultMain Arguments{..} = do
logger <- argsLogger
hSetBuffering stderr LineBuffering

let hlsPlugin = asGhcIdePlugin argsDefaultHlsConfig argsHlsPlugins
let hlsPlugin = asGhcIdePlugin argsHlsPlugins
hlsCommands = allLspCmdIds' pid argsHlsPlugins
plugins = hlsPlugin <> argsGhcidePlugin
options = argsLspOptions { LSP.executeCommandCommands = Just hlsCommands }
argsOnConfigChange _ide = pure . getConfigFromNotification argsDefaultHlsConfig
argsOnConfigChange = getConfigFromNotification
rules = argsRules >> pluginRules plugins

debouncer <- argsDebouncer
Expand All @@ -158,7 +158,7 @@ defaultMain Arguments{..} = do
t <- offsetTime
hPutStrLn stderr "Starting LSP server..."
hPutStrLn stderr "If you are seeing this in a terminal, you probably should have run ghcide WITHOUT the --lsp option!"
runLanguageServer options inH outH argsGetHieDbLoc argsOnConfigChange (pluginHandlers plugins) $ \env vfs rootPath hiedb hieChan -> do
runLanguageServer options inH outH argsGetHieDbLoc argsDefaultHlsConfig argsOnConfigChange (pluginHandlers plugins) $ \env vfs rootPath hiedb hieChan -> do
t <- t
hPutStrLn stderr $ "Started LSP server in " ++ showDuration t

Expand Down Expand Up @@ -214,7 +214,7 @@ defaultMain Arguments{..} = do
putStrLn "\nStep 3/4: Initializing the IDE"
vfs <- makeVFSHandle
sessionLoader <- loadSessionWithOptions argsSessionLoadingOptions dir
let options = (argsIdeOptions Nothing sessionLoader)
let options = (argsIdeOptions argsDefaultHlsConfig sessionLoader)
{ optCheckParents = pure NeverCheck
, optCheckProject = pure False
}
Expand Down
11 changes: 9 additions & 2 deletions ghcide/src/Development/IDE/Plugin/CodeAction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ codeAction state _ (CodeActionParams _ _ (TextDocumentIdentifier uri) _range Cod
actions =
[ mkCA title kind isPreferred [x] edit
| x <- xs, (title, kind, isPreferred, tedit) <- suggestAction $ CodeActionArgs exportsMap ideOptions parsedModule text df annotatedPS tcM har bindings gblSigs x
, let edit = WorkspaceEdit (Just $ Map.singleton uri $ List tedit) Nothing
, let edit = WorkspaceEdit (Just $ Map.singleton uri $ List tedit) Nothing Nothing
]
actions' = caRemoveRedundantImports parsedModule text diag xs uri
<> actions
Expand All @@ -126,7 +126,7 @@ codeAction state _ (CodeActionParams _ _ (TextDocumentIdentifier uri) _range Cod

mkCA :: T.Text -> Maybe CodeActionKind -> Maybe Bool -> [Diagnostic] -> WorkspaceEdit -> (Command |? CodeAction)
mkCA title kind isPreferred diags edit =
InR $ CodeAction title kind (Just $ List diags) isPreferred Nothing (Just edit) Nothing
InR $ CodeAction title kind (Just $ List diags) isPreferred Nothing (Just edit) Nothing Nothing

suggestAction :: CodeActionArgs -> GhcideCodeActions
suggestAction caa =
Expand Down Expand Up @@ -282,6 +282,7 @@ caRemoveRedundantImports m contents digs ctxDigs uri
removeSingle title tedit diagnostic = mkCA title (Just CodeActionQuickFix) Nothing [diagnostic] WorkspaceEdit{..} where
_changes = Just $ Map.singleton uri $ List tedit
_documentChanges = Nothing
_changeAnnotations = Nothing
removeAll tedit = InR $ CodeAction{..} where
_changes = Just $ Map.singleton uri $ List tedit
_title = "Remove all redundant imports"
Expand All @@ -292,6 +293,8 @@ caRemoveRedundantImports m contents digs ctxDigs uri
_isPreferred = Nothing
_command = Nothing
_disabled = Nothing
_xdata = Nothing
_changeAnnotations = Nothing

caRemoveInvalidExports :: Maybe ParsedModule -> Maybe T.Text -> [Diagnostic] -> [Diagnostic] -> Uri -> [Command |? CodeAction]
caRemoveInvalidExports m contents digs ctxDigs uri
Expand Down Expand Up @@ -328,6 +331,8 @@ caRemoveInvalidExports m contents digs ctxDigs uri
_command = Nothing
_isPreferred = Nothing
_disabled = Nothing
_xdata = Nothing
_changeAnnotations = Nothing
removeAll [] = Nothing
removeAll ranges = Just $ InR $ CodeAction{..} where
tedit = concatMap (\r -> [TextEdit r ""]) ranges
Expand All @@ -340,6 +345,8 @@ caRemoveInvalidExports m contents digs ctxDigs uri
_command = Nothing
_isPreferred = Nothing
_disabled = Nothing
_xdata = Nothing
_changeAnnotations = Nothing

suggestRemoveRedundantExport :: ParsedModule -> Diagnostic -> Maybe (T.Text, [Range])
suggestRemoveRedundantExport ParsedModule{pm_parsed_source = L _ HsModule{..}} Diagnostic{..}
Expand Down
1 change: 1 addition & 0 deletions ghcide/src/Development/IDE/Plugin/CodeAction/ExactPrint.hs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ rewriteToWEdit dflags uri anns r = do
WorkspaceEdit
{ _changes = Just (fromList [(uri, List edits)])
, _documentChanges = Nothing
, _changeAnnotations = Nothing
}

------------------------------------------------------------------------------
Expand Down
9 changes: 5 additions & 4 deletions ghcide/src/Development/IDE/Plugin/Completions/Logic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ mkCompl
_filterText = Nothing,
_insertText = Just insertText,
_insertTextFormat = Just Snippet,
_insertTextMode = Nothing,
_textEdit = Nothing,
_additionalTextEdits = Nothing,
_commitCharacters = Nothing,
Expand Down Expand Up @@ -272,27 +273,27 @@ mkModCompl :: T.Text -> CompletionItem
mkModCompl label =
CompletionItem label (Just CiModule) Nothing Nothing
Nothing Nothing Nothing Nothing Nothing Nothing Nothing
Nothing Nothing Nothing Nothing Nothing
Nothing Nothing Nothing Nothing Nothing Nothing

mkImportCompl :: T.Text -> T.Text -> CompletionItem
mkImportCompl enteredQual label =
CompletionItem m (Just CiModule) Nothing (Just label)
Nothing Nothing Nothing Nothing Nothing Nothing Nothing
Nothing Nothing Nothing Nothing Nothing
Nothing Nothing Nothing Nothing Nothing Nothing
where
m = fromMaybe "" (T.stripPrefix enteredQual label)

mkExtCompl :: T.Text -> CompletionItem
mkExtCompl label =
CompletionItem label (Just CiKeyword) Nothing Nothing
Nothing Nothing Nothing Nothing Nothing Nothing Nothing
Nothing Nothing Nothing Nothing Nothing
Nothing Nothing Nothing Nothing Nothing Nothing

mkPragmaCompl :: T.Text -> T.Text -> CompletionItem
mkPragmaCompl label insertText =
CompletionItem label (Just CiKeyword) Nothing Nothing
Nothing Nothing Nothing Nothing Nothing (Just insertText) (Just Snippet)
Nothing Nothing Nothing Nothing Nothing
Nothing Nothing Nothing Nothing Nothing Nothing


cacheDataProducer :: Uri -> HscEnvEq -> Module -> GlobalRdrEnv-> GlobalRdrEnv -> [LImportDecl GhcPs] -> IO CachedCompletions
Expand Down
21 changes: 10 additions & 11 deletions ghcide/src/Development/IDE/Plugin/HLS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import Data.Either
import qualified Data.List as List
import Data.List.NonEmpty (NonEmpty, nonEmpty, toList)
import qualified Data.Map as Map
import Data.Maybe (fromMaybe)
import Data.String
import qualified Data.Text as T
import Development.IDE.Core.Shake
Expand All @@ -44,12 +43,12 @@ import UnliftIO.Exception (catchAny)
--

-- | Map a set of plugins to the underlying ghcide engine.
asGhcIdePlugin :: Config -> IdePlugins IdeState -> Plugin Config
asGhcIdePlugin defaultConfig mp =
asGhcIdePlugin :: IdePlugins IdeState -> Plugin Config
asGhcIdePlugin mp =
mkPlugin rulesPlugins HLS.pluginRules <>
mkPlugin executeCommandPlugins HLS.pluginCommands <>
mkPlugin (extensiblePlugins defaultConfig) HLS.pluginHandlers <>
mkPlugin (extensibleNotificationPlugins defaultConfig) HLS.pluginNotificationHandlers
mkPlugin extensiblePlugins HLS.pluginHandlers <>
mkPlugin extensibleNotificationPlugins HLS.pluginNotificationHandlers
where
ls = Map.toList (ipMap mp)

Expand Down Expand Up @@ -133,8 +132,8 @@ executeCommandHandlers ecs = requestHandler SWorkspaceExecuteCommand execCmd

-- ---------------------------------------------------------------------

extensiblePlugins :: Config -> [(PluginId, PluginHandlers IdeState)] -> Plugin Config
extensiblePlugins defaultConfig xs = Plugin mempty handlers
extensiblePlugins :: [(PluginId, PluginHandlers IdeState)] -> Plugin Config
extensiblePlugins xs = Plugin mempty handlers
where
IdeHandlers handlers' = foldMap bakePluginId xs
bakePluginId :: (PluginId, PluginHandlers IdeState) -> IdeHandlers
Expand All @@ -144,7 +143,7 @@ extensiblePlugins defaultConfig xs = Plugin mempty handlers
handlers = mconcat $ do
(IdeMethod m :=> IdeHandler fs') <- DMap.assocs handlers'
pure $ requestHandler m $ \ide params -> do
config <- fromMaybe defaultConfig <$> Ide.PluginUtils.getClientConfig
config <- Ide.PluginUtils.getClientConfig
let fs = filter (\(pid,_) -> pluginEnabled m pid config) fs'
case nonEmpty fs of
Nothing -> pure $ Left $ ResponseError InvalidRequest
Expand All @@ -161,8 +160,8 @@ extensiblePlugins defaultConfig xs = Plugin mempty handlers
pure $ Right $ combineResponses m config caps params xs
-- ---------------------------------------------------------------------

extensibleNotificationPlugins :: Config -> [(PluginId, PluginNotificationHandlers IdeState)] -> Plugin Config
extensibleNotificationPlugins defaultConfig xs = Plugin mempty handlers
extensibleNotificationPlugins :: [(PluginId, PluginNotificationHandlers IdeState)] -> Plugin Config
extensibleNotificationPlugins xs = Plugin mempty handlers
where
IdeNotificationHandlers handlers' = foldMap bakePluginId xs
bakePluginId :: (PluginId, PluginNotificationHandlers IdeState) -> IdeNotificationHandlers
Expand All @@ -172,7 +171,7 @@ extensibleNotificationPlugins defaultConfig xs = Plugin mempty handlers
handlers = mconcat $ do
(IdeNotification m :=> IdeNotificationHandler fs') <- DMap.assocs handlers'
pure $ notificationHandler m $ \ide params -> do
config <- fromMaybe defaultConfig <$> Ide.PluginUtils.getClientConfig
config <- Ide.PluginUtils.getClientConfig
let fs = filter (\(pid,_) -> plcGlobalOn $ configForPlugin config pid) fs'
case nonEmpty fs of
Nothing -> do
Expand Down
2 changes: 1 addition & 1 deletion ghcide/src/Development/IDE/Plugin/TypeLenses.hs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ codeLensProvider ideState pId CodeLensParams{_textDocument = TextDocumentIdentif
diag <- getDiagnostics ideState
hDiag <- getHiddenDiagnostics ideState

let toWorkSpaceEdit tedit = WorkspaceEdit (Just $ Map.singleton uri $ List tedit) Nothing
let toWorkSpaceEdit tedit = WorkspaceEdit (Just $ Map.singleton uri $ List tedit) Nothing Nothing
generateLensForGlobal sig@GlobalBindingTypeSig{..} = do
range <- srcSpanToRange $ gbSrcSpan sig
tedit <- gblBindingTypeSigToEdit sig
Expand Down
2 changes: 1 addition & 1 deletion ghcide/src/Development/IDE/Spans/AtPoint.hs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ toUri = fromNormalizedUri . filePathToUri' . toNormalizedFilePath'

defRowToSymbolInfo :: Res DefRow -> Maybe SymbolInformation
defRowToSymbolInfo (DefRow{..}:.(modInfoSrcFile -> Just srcFile))
= Just $ SymbolInformation (showGhc defNameOcc) kind Nothing loc Nothing
= Just $ SymbolInformation (showGhc defNameOcc) kind Nothing Nothing loc Nothing
where
kind
| isVarOcc defNameOcc = SkVariable
Expand Down
Loading

0 comments on commit e43ab3f

Please sign in to comment.