Skip to content

Commit be71eb9

Browse files
committed
resolve support works on VSCode (tests need to be redone)
1 parent bb742b3 commit be71eb9

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

plugins/hls-overloaded-record-dot-plugin/src/Ide/Plugin/OverloadedRecordDot.hs

+11-13
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import Control.Monad (replicateM)
1818
import Control.Monad.IO.Class (MonadIO, liftIO)
1919
import Control.Monad.Trans.Class (lift)
2020
import Control.Monad.Trans.Except (ExceptT)
21-
import Data.Aeson (FromJSON, ToJSON, decode,
22-
encode, fromJSON, toJSON)
21+
import Data.Aeson (FromJSON, Result (..),
22+
ToJSON, fromJSON, toJSON)
2323
import Data.Generics (GenericQ, everything,
2424
everythingBut, mkQ)
2525
import qualified Data.IntMap.Strict as IntMap
@@ -148,30 +148,28 @@ instance NFData RecordSelectorExpr where
148148
rnf = rwhnf
149149

150150
data ORDResolveData = ORDRD {
151-
uri :: NormalizedFilePath
151+
uri :: Uri
152152
, uniqueID :: Int
153153
} deriving (Generic, Show)
154154
instance ToJSON ORDResolveData
155155
instance FromJSON ORDResolveData
156156

157-
-- TODO: move the orphans to their packages
158-
instance ToJSON NormalizedFilePath
159-
instance FromJSON NormalizedFilePath
160-
instance ToJSON NormalizedUri
161-
instance FromJSON NormalizedUri
162157
descriptor :: Recorder (WithPriority Log) -> PluginId
163158
-> PluginDescriptor IdeState
164159
descriptor recorder plId = (defaultPluginDescriptor plId)
165160
{ pluginHandlers =
166-
mkPluginHandler SMethod_TextDocumentCodeAction codeActionProvider <> mkPluginHandler SMethod_CodeActionResolve resolveProvider
161+
mkPluginHandler SMethod_TextDocumentCodeAction codeActionProvider
162+
<> mkPluginHandler SMethod_CodeActionResolve resolveProvider
163+
167164
, pluginRules = collectRecSelsRule recorder
168165
}
169166

170167
resolveProvider :: PluginMethodHandler IdeState 'Method_CodeActionResolve
171168
resolveProvider ideState pId ca@(CodeAction _ _ _ _ _ _ _ (Just resData)) =
172169
pluginResponse $ do
173-
case decode . encode $ resData of
174-
Just (ORDRD nfp int) -> do
170+
case fromJSON $ resData of
171+
Success (ORDRD uri int) -> do
172+
nfp <- getNormalizedFilePath uri
175173
CRSR _ crsDetails exts <- collectRecSelResult ideState nfp
176174
pragma <- getFirstPragma pId ideState nfp
177175
let pragmaEdit =
@@ -205,15 +203,15 @@ codeActionProvider ideState pId (CodeActionParams _ _ caDocId caRange _) =
205203
edits _ = []
206204
changes crsM crsD =
207205
case supportsResolve of
208-
Just True -> Just $ WorkspaceEdit
206+
Just False -> Just $ WorkspaceEdit
209207
(Just (Map.singleton (fromNormalizedUri
210208
(normalizedFilePathToUri nfp))
211209
(edits (IntMap.lookup crsM crsD))))
212210
Nothing Nothing
213211
_ -> Nothing
214212
resolveData crsM =
215213
case supportsResolve of
216-
Just True -> Just $ toJSON $ ORDRD nfp crsM
214+
Just True -> Just $ toJSON $ ORDRD (caDocId ^. L.uri) crsM
217215
_ -> Nothing
218216
mkCodeAction crsD crsM = InR CodeAction
219217
{ -- We pass the record selector to the title function, so that

0 commit comments

Comments
 (0)