Skip to content

Commit 54c693e

Browse files
author
kokobd
committed
add selection range support
1 parent 9c2bc32 commit 54c693e

File tree

20 files changed

+552
-66
lines changed

20 files changed

+552
-66
lines changed

.github/workflows/hackage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
"hls-refine-imports-plugin", "hls-retrie-plugin",
3333
"hls-splice-plugin", "hls-tactics-plugin",
3434
"hls-call-hierarchy-plugin", "hls-alternate-number-format-plugin",
35-
"hls-qualify-imported-names-plugin",
35+
"hls-qualify-imported-names-plugin", "hls-selection-range-plugin",
3636
"haskell-language-server"]
3737
ghc: [ "9.0.1",
3838
"8.10.7",

cabal.project

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ packages:
2626
./plugins/hls-call-hierarchy-plugin
2727
./plugins/hls-alternate-number-format-plugin
2828
./plugins/hls-qualify-imported-names-plugin
29+
./plugins/hls-selection-range-plugin
2930

3031
-- Standard location for temporary packages needed for particular environments
3132
-- For example it is used in the project gitlab mirror to help in the MAcOS M1 build script
@@ -38,6 +39,24 @@ package *
3839
ghc-options: -haddock
3940
test-show-details: direct
4041

42+
source-repository-package
43+
type: git
44+
location: https://github.com/haskell/lsp.git
45+
tag: bad3d45854e5ca4eaf53985e9cee42d25840d18a
46+
subdir: lsp-types
47+
48+
source-repository-package
49+
type: git
50+
location: https://github.com/haskell/lsp.git
51+
tag: bad3d45854e5ca4eaf53985e9cee42d25840d18a
52+
subdir: lsp
53+
54+
source-repository-package
55+
type: git
56+
location: https://github.com/haskell/lsp.git
57+
tag: bad3d45854e5ca4eaf53985e9cee42d25840d18a
58+
subdir: lsp-test
59+
4160
write-ghc-environment-files: never
4261

4362
index-state: 2022-01-10T17:57:05Z

exe/Plugins.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ import Ide.Plugin.Splice as Splice
7272
import Ide.Plugin.AlternateNumberFormat as AlternateNumberFormat
7373
#endif
7474

75+
#if selectionRange
76+
import Ide.Plugin.SelectionRange as SelectionRange
77+
#endif
78+
7579
-- formatters
7680

7781
#if floskell
@@ -167,6 +171,9 @@ idePlugins includeExamples = pluginDescToIdePlugins allPlugins
167171
#endif
168172
#if alternateNumberFormat
169173
AlternateNumberFormat.descriptor "alternateNumberFormat" :
174+
#endif
175+
#if selectionRange
176+
SelectionRange.descriptor "selectionRange" :
170177
#endif
171178
-- The ghcide descriptors should come last so that the notification handlers
172179
-- (which restart the Shake build) run after everything else

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ module Development.IDE.Plugin.HLS.GhcIde
99
import Control.Monad.IO.Class
1010
import Development.IDE
1111
import Development.IDE.LSP.HoverDefinition
12-
import qualified Development.IDE.LSP.Notifications as Notifications
12+
import qualified Development.IDE.LSP.Notifications as Notifications
1313
import Development.IDE.LSP.Outline
14-
import qualified Development.IDE.Plugin.CodeAction as CodeAction
15-
import qualified Development.IDE.Plugin.Completions as Completions
16-
import qualified Development.IDE.Plugin.TypeLenses as TypeLenses
14+
import qualified Development.IDE.Plugin.CodeAction as CodeAction
15+
import qualified Development.IDE.Plugin.Completions as Completions
16+
import qualified Development.IDE.Plugin.TypeLenses as TypeLenses
1717
import Ide.Types
18-
import Language.LSP.Server (LspM)
18+
import Language.LSP.Server (LspM)
1919
import Language.LSP.Types
20-
import Text.Regex.TDFA.Text ()
20+
import Text.Regex.TDFA.Text ()
2121

2222
descriptors :: [PluginDescriptor IdeState]
2323
descriptors =

haskell-language-server.cabal

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ flag qualifyImportedNames
173173
default: True
174174
manual: True
175175

176+
flag selectionRange
177+
description: Enable selectionRange plugin
178+
default: True
179+
manual: True
180+
176181
-- formatters
177182

178183
flag floskell
@@ -280,6 +285,11 @@ common qualifyImportedNames
280285
build-depends: hls-qualify-imported-names-plugin ^>=1.0.0.0
281286
cpp-options: -DqualifyImportedNames
282287

288+
common selectionRange
289+
if flag(selectionRange)
290+
build-depends: hls-selection-range-plugin ^>=1.0.0.0
291+
cpp-options: -DselectionRange
292+
283293
-- formatters
284294

285295
common floskell
@@ -329,6 +339,7 @@ executable haskell-language-server
329339
, splice
330340
, alternateNumberFormat
331341
, qualifyImportedNames
342+
, selectionRange
332343
, floskell
333344
, fourmolu
334345
, ormolu

hls-plugin-api/src/Ide/Plugin/Config.hs

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -100,58 +100,62 @@ instance A.ToJSON Config where
100100
-- This provides a regular naming scheme for all plugin config.
101101
data PluginConfig =
102102
PluginConfig
103-
{ plcGlobalOn :: !Bool
104-
, plcCallHierarchyOn :: !Bool
105-
, plcCodeActionsOn :: !Bool
106-
, plcCodeLensOn :: !Bool
107-
, plcDiagnosticsOn :: !Bool
108-
, plcHoverOn :: !Bool
109-
, plcSymbolsOn :: !Bool
110-
, plcCompletionOn :: !Bool
111-
, plcRenameOn :: !Bool
112-
, plcConfig :: !A.Object
103+
{ plcGlobalOn :: !Bool
104+
, plcCallHierarchyOn :: !Bool
105+
, plcCodeActionsOn :: !Bool
106+
, plcCodeLensOn :: !Bool
107+
, plcDiagnosticsOn :: !Bool
108+
, plcHoverOn :: !Bool
109+
, plcSymbolsOn :: !Bool
110+
, plcCompletionOn :: !Bool
111+
, plcRenameOn :: !Bool
112+
, plcSelectionRangeOn :: !Bool
113+
, plcConfig :: !A.Object
113114
} deriving (Show,Eq)
114115

115116
instance Default PluginConfig where
116117
def = PluginConfig
117-
{ plcGlobalOn = True
118-
, plcCallHierarchyOn = True
119-
, plcCodeActionsOn = True
120-
, plcCodeLensOn = True
121-
, plcDiagnosticsOn = True
122-
, plcHoverOn = True
123-
, plcSymbolsOn = True
124-
, plcCompletionOn = True
125-
, plcRenameOn = True
126-
, plcConfig = mempty
118+
{ plcGlobalOn = True
119+
, plcCallHierarchyOn = True
120+
, plcCodeActionsOn = True
121+
, plcCodeLensOn = True
122+
, plcDiagnosticsOn = True
123+
, plcHoverOn = True
124+
, plcSymbolsOn = True
125+
, plcCompletionOn = True
126+
, plcRenameOn = True
127+
, plcSelectionRangeOn = True
128+
, plcConfig = mempty
127129
}
128130

129131
instance A.ToJSON PluginConfig where
130-
toJSON (PluginConfig g ch ca cl d h s c rn cfg) = r
132+
toJSON (PluginConfig g ch ca cl d h s c rn sr cfg) = r
131133
where
132-
r = object [ "globalOn" .= g
133-
, "callHierarchyOn" .= ch
134-
, "codeActionsOn" .= ca
135-
, "codeLensOn" .= cl
136-
, "diagnosticsOn" .= d
137-
, "hoverOn" .= h
138-
, "symbolsOn" .= s
139-
, "completionOn" .= c
140-
, "renameOn" .= rn
141-
, "config" .= cfg
134+
r = object [ "globalOn" .= g
135+
, "callHierarchyOn" .= ch
136+
, "codeActionsOn" .= ca
137+
, "codeLensOn" .= cl
138+
, "diagnosticsOn" .= d
139+
, "hoverOn" .= h
140+
, "symbolsOn" .= s
141+
, "completionOn" .= c
142+
, "renameOn" .= rn
143+
, "selectionRangeOn" .= sr
144+
, "config" .= cfg
142145
]
143146

144147
instance A.FromJSON PluginConfig where
145148
parseJSON = A.withObject "PluginConfig" $ \o -> PluginConfig
146-
<$> o .:? "globalOn" .!= plcGlobalOn def
147-
<*> o .:? "callHierarchyOn" .!= plcCallHierarchyOn def
148-
<*> o .:? "codeActionsOn" .!= plcCodeActionsOn def
149-
<*> o .:? "codeLensOn" .!= plcCodeLensOn def
150-
<*> o .:? "diagnosticsOn" .!= plcDiagnosticsOn def -- AZ
151-
<*> o .:? "hoverOn" .!= plcHoverOn def
152-
<*> o .:? "symbolsOn" .!= plcSymbolsOn def
153-
<*> o .:? "completionOn" .!= plcCompletionOn def
154-
<*> o .:? "renameOn" .!= plcRenameOn def
155-
<*> o .:? "config" .!= plcConfig def
149+
<$> o .:? "globalOn" .!= plcGlobalOn def
150+
<*> o .:? "callHierarchyOn" .!= plcCallHierarchyOn def
151+
<*> o .:? "codeActionsOn" .!= plcCodeActionsOn def
152+
<*> o .:? "codeLensOn" .!= plcCodeLensOn def
153+
<*> o .:? "diagnosticsOn" .!= plcDiagnosticsOn def -- AZ
154+
<*> o .:? "hoverOn" .!= plcHoverOn def
155+
<*> o .:? "symbolsOn" .!= plcSymbolsOn def
156+
<*> o .:? "completionOn" .!= plcCompletionOn def
157+
<*> o .:? "renameOn" .!= plcRenameOn def
158+
<*> o .:? "selectionRangeOn" .!= plcSelectionRangeOn def
159+
<*> o .:? "config" .!= plcConfig def
156160

157161
-- ---------------------------------------------------------------------

hls-plugin-api/src/Ide/Types.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,10 @@ instance PluginMethod TextDocumentRangeFormatting where
284284
instance PluginMethod TextDocumentPrepareCallHierarchy where
285285
pluginEnabled _ = pluginEnabledConfig plcCallHierarchyOn
286286

287+
instance PluginMethod TextDocumentSelectionRange where
288+
pluginEnabled _ = pluginEnabledConfig plcSelectionRangeOn
289+
combineResponses _ _ _ _ (x :| _) = x
290+
287291
instance PluginMethod CallHierarchyIncomingCalls where
288292
pluginEnabled _ = pluginEnabledConfig plcCallHierarchyOn
289293

0 commit comments

Comments
 (0)