Skip to content

Commit 66f5526

Browse files
authored
Change tracking of file types to language kinds (#4621)
The plugin descriptor now tracks the language kinds it is responsible for instead of the file endings. We get the language kinds of any file from the VFS. Currently we are using a source repository to be able to use the lsp changes needed, but once lsp is released this can be removed.
1 parent b3b71b7 commit 66f5526

16 files changed

Lines changed: 116 additions & 100 deletions

File tree

cabal.project

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ packages:
66
./hls-plugin-api
77
./hls-test-utils
88

9-
10-
index-state: 2026-02-02T09:03:26Z
9+
index-state: 2026-02-24T00:00:00Z
1110

1211
tests: True
1312
test-show-details: direct
@@ -41,6 +40,7 @@ constraints:
4140
-- We want to be able to benefit from the performance optimisations
4241
-- in the future, thus: TODO: remove this flag.
4342
bitvec -simd,
43+
monad-control >=1.0.3,
4444

4545

4646
-- Some of the formatters need the latest Cabal-syntax version,
@@ -59,15 +59,11 @@ if impl(ghc >= 9.11)
5959

6060
if impl(ghc >= 9.14)
6161
allow-newer:
62-
lsp-types:containers,
63-
lsp:containers,
6462
indexed-traversable:containers,
6563
quickcheck-instances:containers,
6664
dependent-map:containers,
6765
aeson:containers,
6866
semialign:containers,
69-
lsp-test:containers,
70-
hie-bios:ghc,
7167
string-interpolate:template-haskell,
7268
tasty-hspec:base,
7369
tagged:template-haskell,
@@ -79,19 +75,20 @@ if impl(ghc >= 9.14)
7975
some:base,
8076
boring:base,
8177
indexed-traversable-instances:base,
82-
lsp-types:template-haskell,
8378
uuid-types:template-haskell,
8479
hie-compat:base,
85-
hie-bios:time,
86-
hie-bios:template-haskell,
8780
ghc-trace-events:base,
8881
constraints-extras:template-haskell,
8982
aeson:time,
9083
text-iso8601:time,
9184
semialign:base,
9285
aeson:template-haskell,
93-
lsp-test:time,
9486
lukko:base,
9587
binary-instances:base,
9688
binary-orphans:base,
97-
cabal-install-parsers:containers
89+
cabal-install-parsers:containers,
90+
haddock-library:base,
91+
websockets:containers,
92+
monad-control:transformers,
93+
mmorph:transformers-compat,
94+
binary-instances:tagged,

ghcide-test/exe/InitializeResponseTests.hs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,14 @@ tests = withResource acquire release tests where
5555
{ _supported = Just True
5656
, _changeNotifications = Just (InR True)
5757
}
58-
, _fileOperations = Nothing
58+
, _fileOperations = Just $ FileOperationOptions
59+
{ _didCreate = Nothing
60+
, _willCreate = Nothing
61+
, _didRename = Nothing
62+
, _willRename = Nothing
63+
, _didDelete = Nothing
64+
, _willDelete = Nothing
65+
}
5966
})
6067
, chk "NO experimental" (^. L.experimental) Nothing
6168
] where

ghcide/ghcide.cabal

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,16 @@ library
7474
, Glob
7575
, haddock-library >=1.8 && <1.12
7676
, hashable
77-
, hie-bios ^>=0.17.0
77+
, hie-bios ^>= 0.18.0
7878
, hiedb ^>= 0.8.0.0
7979
, hls-graph == 2.13.0.0
8080
, hls-plugin-api == 2.13.0.0
8181
, implicit-hie >= 0.1.4.0 && < 0.1.5
8282
, lens
8383
, lens-aeson
8484
, list-t
85-
, lsp ^>=2.7
86-
, lsp-types ^>=2.3
85+
, lsp ^>=2.8
86+
, lsp-types ^>=2.4
8787
, mtl
8888
, opentelemetry >=0.6.1
8989
, optparse-applicative

ghcide/src/Development/IDE/Core/FileStore.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ getVersionedTextDoc doc = do
252252
maybe (pure Nothing) getVirtualFile $
253253
uriToNormalizedFilePath $ toNormalizedUri uri
254254
let ver = case mvf of
255-
Just (VirtualFile lspver _ _) -> lspver
256-
Nothing -> 0
255+
Just (VirtualFile lspver _ _ _) -> lspver
256+
Nothing -> 0
257257
return (VersionedTextDocumentIdentifier uri ver)
258258

259259
fileStoreRules :: Recorder (WithPriority Log) -> (NormalizedFilePath -> Action Bool) -> Rules ()

ghcide/src/Development/IDE/Core/Rules.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ import Ide.Plugin.Properties (HasProperty,
167167
useProperty,
168168
usePropertyByPath)
169169
import Ide.Types (DynFlagsModifications (dynFlagsModifyGlobal, dynFlagsModifyParser),
170-
PluginId)
170+
PluginId, getVirtualFileFromVFS)
171171
import qualified Language.LSP.Protocol.Lens as JL
172172
import Language.LSP.Protocol.Message (SMethod (SMethod_CustomMethod, SMethod_WindowShowMessage))
173173
import Language.LSP.Protocol.Types (MessageType (MessageType_Info),
@@ -525,7 +525,7 @@ persistentHieFileRule recorder = addPersistentRule GetHieAst $ \file -> runMaybe
525525
res <- readHieFileForSrcFromDisk recorder file
526526
vfsRef <- asks vfsVar
527527
vfsData <- liftIO $ _vfsMap <$> readTVarIO vfsRef
528-
(currentSource, ver) <- liftIO $ case M.lookup (filePathToUri' file) vfsData of
528+
(currentSource, ver) <- liftIO $ case getVirtualFileFromVFS (VFS vfsData) (filePathToUri' file) of
529529
Nothing -> (,Nothing) . T.decodeUtf8 <$> BS.readFile (fromNormalizedFilePath file)
530530
Just vf -> pure (virtualFileText vf, Just $ virtualFileVersion vf)
531531
let refmap = generateReferencesMap . getAsts . Compat.hie_asts $ res

ghcide/src/Development/IDE/Core/Shake.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ import Development.IDE.Core.RuleTypes
130130
import Development.IDE.Types.Options as Options
131131
import qualified Language.LSP.Protocol.Message as LSP
132132
import qualified Language.LSP.Server as LSP
133+
import qualified Language.LSP.VFS as VFS
133134

134135
import Development.IDE.Core.Tracing
135136
import Development.IDE.Core.WorkerThread
@@ -401,7 +402,8 @@ class Typeable a => IsIdeGlobal a where
401402
getVirtualFile :: NormalizedFilePath -> Action (Maybe VirtualFile)
402403
getVirtualFile nf = do
403404
vfs <- fmap _vfsMap . liftIO . readTVarIO . vfsVar =<< getShakeExtras
404-
pure $! Map.lookup (filePathToUri' nf) vfs -- Don't leak a reference to the entire map
405+
pure $! -- Don't leak a reference to the entire map
406+
getVirtualFileFromVFS (VFS vfs) $ filePathToUri' nf
405407

406408
-- Take a snapshot of the current LSP VFS
407409
vfsSnapshot :: Maybe (LSP.LanguageContextEnv a) -> IO VFS

ghcide/src/Development/IDE/Plugin/Completions/Logic.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ mergeListsBy cmp all_lists = merge_lists all_lists
867867

868868
-- |From the given cursor position, gets the prefix module or record for autocompletion
869869
getCompletionPrefix :: Position -> VFS.VirtualFile -> PosPrefixInfo
870-
getCompletionPrefix pos (VFS.VirtualFile _ _ ropetext) = getCompletionPrefixFromRope pos ropetext
870+
getCompletionPrefix pos (VFS.VirtualFile _ _ ropetext _) = getCompletionPrefixFromRope pos ropetext
871871

872872
getCompletionPrefixFromRope :: Position -> Rope.Rope -> PosPrefixInfo
873873
getCompletionPrefixFromRope pos@(Position l c) ropetext =

ghcide/src/Development/IDE/Plugin/HLS.hs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ import qualified Language.LSP.Server as LSP
4949
import Language.LSP.VFS
5050
import Prettyprinter.Render.String (renderString)
5151
import Text.Regex.TDFA.Text ()
52-
import UnliftIO (MonadUnliftIO, liftIO)
52+
import UnliftIO (MonadUnliftIO, liftIO,
53+
readTVarIO)
5354
import UnliftIO.Async (forConcurrently)
5455
import UnliftIO.Exception (catchAny)
5556

@@ -251,11 +252,12 @@ extensiblePlugins recorder plugins = mempty { P.pluginHandlers = handlers }
251252
handlers = mconcat $ do
252253
(IdeMethod m :=> IdeHandler fs') <- DMap.assocs handlers'
253254
pure $ requestHandler m $ \ide params -> do
255+
vfs <- readTVarIO $ vfsVar $ shakeExtras ide
254256
config <- Ide.PluginUtils.getClientConfig
255257
-- Only run plugins that are allowed to run on this request, save the
256258
-- list of disabled plugins incase that's all we have
257-
let (fs, dfs) = List.partition (\(_, desc, _) -> handlesRequest m params desc config == HandlesRequest) fs'
258-
let disabledPluginsReason = (\(x, desc, _) -> (x, handlesRequest m params desc config)) <$> dfs
259+
let (fs, dfs) = List.partition (\(_, desc, _) -> handlesRequest vfs m params desc config == HandlesRequest) fs'
260+
let disabledPluginsReason = (\(x, desc, _) -> (x, handlesRequest vfs m params desc config)) <$> dfs
259261
-- Clients generally don't display ResponseErrors so instead we log any that we come across
260262
-- However, some clients do display ResponseErrors! See for example the issues:
261263
-- https://github.com/haskell/haskell-language-server/issues/4467
@@ -370,7 +372,7 @@ extensibleNotificationPlugins recorder xs = mempty { P.pluginHandlers = handlers
370372
pure $ notificationHandler m $ \ide vfs params -> do
371373
config <- Ide.PluginUtils.getClientConfig
372374
-- Only run plugins that are enabled for this request
373-
let fs = filter (\(_, desc, _) -> handlesRequest m params desc config == HandlesRequest) fs'
375+
let fs = filter (\(_, desc, _) -> handlesRequest vfs m params desc config == HandlesRequest) fs'
374376
case nonEmpty fs of
375377
Nothing -> do
376378
logWith recorder Warning (LogNoPluginForMethod $ Some m)

haskell-language-server.cabal

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,8 @@ library hls-cabal-plugin
279279
, hls-plugin-api == 2.13.0.0
280280
, hls-graph == 2.13.0.0
281281
, lens
282-
, lsp ^>=2.7
283-
, lsp-types ^>=2.3
282+
, lsp ^>=2.8
283+
, lsp-types ^>=2.4
284284
, mtl
285285
, regex-tdfa ^>=1.3.1
286286
, text
@@ -415,7 +415,7 @@ library hls-call-hierarchy-plugin
415415
, hiedb ^>= 0.8.0.0
416416
, hls-plugin-api == 2.13.0.0
417417
, lens
418-
, lsp >=2.7
418+
, lsp >=2.8
419419
, sqlite-simple
420420
, text
421421

@@ -1040,7 +1040,7 @@ library hls-alternate-number-format-plugin
10401040
, hls-graph
10411041
, hls-plugin-api == 2.13.0.0
10421042
, lens
1043-
, lsp ^>=2.7
1043+
, lsp ^>=2.8
10441044
, mtl
10451045
, syb
10461046
, text
@@ -1268,7 +1268,7 @@ library hls-gadt-plugin
12681268
, hls-plugin-api == 2.13.0.0
12691269
, haskell-language-server:hls-refactor-plugin
12701270
, lens
1271-
, lsp >=2.7
1271+
, lsp >=2.8
12721272
, mtl
12731273
, text
12741274
, transformers
@@ -1315,7 +1315,7 @@ library hls-explicit-fixity-plugin
13151315
, ghcide == 2.13.0.0
13161316
, hashable
13171317
, hls-plugin-api == 2.13.0.0
1318-
, lsp >=2.7
1318+
, lsp >=2.8
13191319
, text
13201320

13211321
default-extensions: DataKinds
@@ -1799,7 +1799,7 @@ library hls-notes-plugin
17991799
, hls-graph == 2.13.0.0
18001800
, hls-plugin-api == 2.13.0.0
18011801
, lens
1802-
, lsp >=2.7
1802+
, lsp >=2.8
18031803
, mtl >= 2.2
18041804
, regex-tdfa >= 1.3.1
18051805
, text
@@ -2104,7 +2104,7 @@ test-suite ghcide-tests
21042104
, lens
21052105
, list-t
21062106
, lsp
2107-
, lsp-test ^>=0.17.1
2107+
, lsp-test ^>=0.18.0
21082108
, lsp-types
21092109
, mtl
21102110
, network-uri
@@ -2261,7 +2261,7 @@ test-suite ghcide-bench-test
22612261
build-depends:
22622262
extra,
22632263
haskell-language-server:ghcide-bench-lib,
2264-
lsp-test ^>= 0.17,
2264+
lsp-test ^>= 0.18,
22652265
tasty,
22662266
tasty-hunit >= 0.10,
22672267
tasty-rerun

hls-plugin-api/hls-plugin-api.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ library
6969
, hls-graph == 2.13.0.0
7070
, lens
7171
, lens-aeson
72-
, lsp ^>=2.7
72+
, lsp ^>=2.8
7373
, megaparsec >=9.0
7474
, mtl
7575
, opentelemetry >=0.4

0 commit comments

Comments
 (0)