Skip to content

Commit ab9cd34

Browse files
July541maralorn
authored andcommitted
modify for hls-tactics-plugin
1 parent 8716794 commit ab9cd34

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

plugins/hls-tactics-plugin/old/src/Wingman/AbstractLSP.hs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,16 @@ import Development.IDE.Core.UseStale
2323
import Development.IDE.GHC.ExactPrint (GetAnnotatedParsedSource(GetAnnotatedParsedSource))
2424
import qualified Ide.Plugin.Config as Plugin
2525
import Ide.Types
26-
import Language.LSP.Server (LspM, sendRequest, getClientCapabilities)
26+
import Language.LSP.Server (LspM, sendRequest, getClientCapabilities, getVersionedTextDoc)
2727
import qualified Language.LSP.Types as LSP
28+
import qualified Language.LSP.Types.Lens as J
2829
import Language.LSP.Types hiding (CodeLens, CodeAction)
2930
import Wingman.AbstractLSP.Types
3031
import Wingman.EmptyCase (fromMaybeT)
3132
import Wingman.LanguageServer (runIde, getTacticConfigAction, getIdeDynflags, mkWorkspaceEdits, runStaleIde, showLspMessage, mkShowMessageParams)
3233
import Wingman.StaticPlugin (enableQuasiQuotes)
3334
import Wingman.Types
35+
import Control.Lens ((^.))
3436

3537

3638
------------------------------------------------------------------------------
@@ -111,7 +113,7 @@ runContinuation plId cont state (fc, b) = do
111113
GraftEdit gr -> do
112114
ccs <- lift getClientCapabilities
113115
TrackedStale pm _ <- mapMaybeT liftIO $ stale GetAnnotatedParsedSource
114-
case mkWorkspaceEdits (enableQuasiQuotes le_dflags) ccs (fc_uri le_fileContext) (unTrack pm) gr of
116+
case mkWorkspaceEdits (enableQuasiQuotes le_dflags) ccs (fc_uri le_fileContext) (textVersion fc) (unTrack pm) gr of
115117
Left errs ->
116118
pure $ Just $ ResponseError
117119
{ _code = InternalError
@@ -176,11 +178,13 @@ codeActionProvider
176178
)
177179
-> PluginMethodHandler IdeState TextDocumentCodeAction
178180
codeActionProvider sort k state plId
179-
(CodeActionParams _ _ (TextDocumentIdentifier uri) range _) = do
181+
(CodeActionParams _ _ docId@(TextDocumentIdentifier uri) range _) = do
182+
version <- (^. J.version) <$> getVersionedTextDoc docId
180183
fromMaybeT (Right $ List []) $ do
181184
let fc = FileContext
182185
{ fc_uri = uri
183186
, fc_range = Just $ unsafeMkCurrent range
187+
, textVersion = version
184188
}
185189
env <- buildEnv state plId fc
186190
args <- fetchTargetArgs @target env
@@ -203,11 +207,13 @@ codeLensProvider
203207
)
204208
-> PluginMethodHandler IdeState TextDocumentCodeLens
205209
codeLensProvider sort k state plId
206-
(CodeLensParams _ _ (TextDocumentIdentifier uri)) = do
210+
(CodeLensParams _ _ docId@(TextDocumentIdentifier uri)) = do
211+
version <- (^. J.version) <$> getVersionedTextDoc docId
207212
fromMaybeT (Right $ List []) $ do
208213
let fc = FileContext
209214
{ fc_uri = uri
210215
, fc_range = Nothing
216+
, textVersion = version
211217
}
212218
env <- buildEnv state plId fc
213219
args <- fetchTargetArgs @target env

plugins/hls-tactics-plugin/old/src/Wingman/AbstractLSP/Types.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ data FileContext = FileContext
124124
, fc_range :: Maybe (Tracked 'Current Range)
125125
-- ^ For code actions, this is 'Just'. For code lenses, you'll get
126126
-- a 'Nothing' in the request, and a 'Just' in the response.
127+
, textVersion :: TextDocumentVersion
127128
}
128129
deriving stock (Eq, Ord, Show, Generic)
129130
deriving anyclass (A.ToJSON, A.FromJSON)

plugins/hls-tactics-plugin/old/src/Wingman/EmptyCase.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ emptyCaseInteraction = Interaction $
6969
(foldMap (hySingleton . occName . fst) bindings)
7070
ty
7171
edits <- liftMaybe $ hush $
72-
mkWorkspaceEdits le_dflags ccs fc_uri (unTrack pm) $
72+
mkWorkspaceEdits le_dflags ccs fc_uri textVersion (unTrack pm) $
7373
graftMatchGroup (RealSrcSpan (unTrack ss) Nothing) $
7474
noLoc matches
7575
pure

plugins/hls-tactics-plugin/old/src/Wingman/LanguageServer.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -622,12 +622,13 @@ mkWorkspaceEdits
622622
:: DynFlags
623623
-> ClientCapabilities
624624
-> Uri
625+
-> TextDocumentVersion
625626
-> Annotated ParsedSource
626627
-> Graft (Either String) ParsedSource
627628
-> Either UserFacingMessage WorkspaceEdit
628-
mkWorkspaceEdits dflags ccs uri pm g = do
629+
mkWorkspaceEdits dflags ccs uri version pm g = do
629630
let pm' = runIdentity $ transformA pm annotateMetaprograms
630-
let response = transform dflags ccs uri g pm'
631+
let response = transform dflags ccs uri version g pm'
631632
in first (InfrastructureError . T.pack) response
632633

633634

0 commit comments

Comments
 (0)