Skip to content

Commit

Permalink
Merge pull request #108 from Bubba/symbol-kinds-and-ver-caps
Browse files Browse the repository at this point in the history
New symbol kinds and versioned capability presets
  • Loading branch information
alanz authored Aug 2, 2018
2 parents 15874cf + 75b0095 commit 9797b27
Show file tree
Hide file tree
Showing 4 changed files with 243 additions and 21 deletions.
2 changes: 2 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* Update ClientCapabilities to v3.10
* Add MarkupContent
* Add new CompletionKinds
* Add new SymbolKinds
* Add preset version capabilities

## 0.4.0.0 -- 2018-07-10

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,13 @@ data SymbolKindClientCapabilities =
-- If this property is not present the client only supports
-- the symbol kinds from `File` to `Array` as defined in
-- the initial version of the protocol.
_valueSet :: List SymbolKind
_valueSet :: Maybe (List SymbolKind)
} deriving (Show, Read, Eq)

$(deriveJSON lspOptions ''SymbolKindClientCapabilities)

instance Default SymbolKindClientCapabilities where
def = SymbolKindClientCapabilities (List allKinds)
def = SymbolKindClientCapabilities (Just $ List allKinds)
where allKinds = [ SkFile
, SkModule
, SkNamespace
Expand All @@ -186,7 +186,7 @@ data SymbolClientCapabilities =
SymbolClientCapabilities
{ _dynamicRegistration :: Maybe Bool -- ^Symbol request supports dynamic
-- registration.
, _symbolKind :: SymbolKindClientCapabilities -- ^ Specific capabilities for the `SymbolKind`.
, _symbolKind :: Maybe SymbolKindClientCapabilities -- ^ Specific capabilities for the `SymbolKind`.
} deriving (Show, Read, Eq)

$(deriveJSON lspOptions ''SymbolClientCapabilities)
Expand Down
61 changes: 43 additions & 18 deletions haskell-lsp-types/src/Language/Haskell/LSP/TH/Symbol.hs
Original file line number Diff line number Diff line change
Expand Up @@ -124,27 +124,44 @@ data SymbolKind
| SkNumber
| SkBoolean
| SkArray
| SkObject
| SkKey
| SkNull
| SkEnumMember
| SkStruct
| SkEvent
| SkOperator
| SkTypeParameter
deriving (Read,Show,Eq)

instance ToJSON SymbolKind where
toJSON SkFile = Number 1
toJSON SkModule = Number 2
toJSON SkNamespace = Number 3
toJSON SkPackage = Number 4
toJSON SkClass = Number 5
toJSON SkMethod = Number 6
toJSON SkProperty = Number 7
toJSON SkField = Number 8
toJSON SkConstructor = Number 9
toJSON SkEnum = Number 10
toJSON SkInterface = Number 11
toJSON SkFunction = Number 12
toJSON SkVariable = Number 13
toJSON SkConstant = Number 14
toJSON SkString = Number 15
toJSON SkNumber = Number 16
toJSON SkBoolean = Number 17
toJSON SkArray = Number 18
toJSON SkFile = Number 1
toJSON SkModule = Number 2
toJSON SkNamespace = Number 3
toJSON SkPackage = Number 4
toJSON SkClass = Number 5
toJSON SkMethod = Number 6
toJSON SkProperty = Number 7
toJSON SkField = Number 8
toJSON SkConstructor = Number 9
toJSON SkEnum = Number 10
toJSON SkInterface = Number 11
toJSON SkFunction = Number 12
toJSON SkVariable = Number 13
toJSON SkConstant = Number 14
toJSON SkString = Number 15
toJSON SkNumber = Number 16
toJSON SkBoolean = Number 17
toJSON SkArray = Number 18
toJSON SkObject = Number 19
toJSON SkKey = Number 20
toJSON SkNull = Number 21
toJSON SkEnumMember = Number 22
toJSON SkStruct = Number 23
toJSON SkEvent = Number 24
toJSON SkOperator = Number 25
toJSON SkTypeParameter = Number 26


instance FromJSON SymbolKind where
parseJSON (Number 1) = pure SkFile
Expand All @@ -165,6 +182,14 @@ instance FromJSON SymbolKind where
parseJSON (Number 16) = pure SkNumber
parseJSON (Number 17) = pure SkBoolean
parseJSON (Number 18) = pure SkArray
parseJSON (Number 19) = pure SkObject
parseJSON (Number 20) = pure SkKey
parseJSON (Number 21) = pure SkNull
parseJSON (Number 22) = pure SkEnumMember
parseJSON (Number 23) = pure SkStruct
parseJSON (Number 24) = pure SkEvent
parseJSON (Number 25) = pure SkOperator
parseJSON (Number 26) = pure SkTypeParameter
parseJSON _ = mempty


Expand Down
195 changes: 195 additions & 0 deletions src/Language/Haskell/LSP/Types/Capabilities.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,201 @@
module Language.Haskell.LSP.Types.Capabilities
(
module Language.Haskell.LSP.TH.ClientCapabilities
, fullCaps
, LSPVersion
, capsForVersion
) where

import Prelude hiding (min)
import Language.Haskell.LSP.TH.ClientCapabilities
import Language.Haskell.LSP.TH.DataTypesJSON

-- | The whole shebang. The real deal.
-- Capabilities for full conformance to the current (v3.10) LSP specification.
fullCaps :: ClientCapabilities
fullCaps = capsForVersion (LSPVersion maxBound maxBound)

-- | A specific version of the LSP specification.
data LSPVersion = LSPVersion Int Int -- ^ Construct a major.minor version

-- | Capabilities for full conformance to the LSP specification up until a version.
-- Some important milestones:
--
-- * 3.9 completion item preselect
-- * 3.8 codeAction literals
-- * 3.7 related information in diagnostics
-- * 3.6 workspace folders, colors, goto type/implementation
-- * 3.4 extended completion item and symbol item kinds
-- * 3.0 dynamic registration
capsForVersion :: LSPVersion -> ClientCapabilities
capsForVersion (LSPVersion maj min) = ClientCapabilities (Just w) (Just td) Nothing
where
w = WorkspaceClientCapabilities
(Just True)
(Just (WorkspaceEditClientCapabilities (Just True)))
(Just (DidChangeConfigurationClientCapabilities dynamicReg))
(Just (DidChangeWatchedFilesClientCapabilities dynamicReg))
(Just symbol)
(Just (ExecuteClientCapabilities dynamicReg))
(since 3 6 True)
(since 3 6 True)

symbol = SymbolClientCapabilities
dynamicReg
(since 3 4 symbolKind)

symbolKind =
SymbolKindClientCapabilities (Just sKs)

sKs
| maj >= 3 && min >= 4 = List (oldSKs ++ newSKs)
| otherwise = List oldSKs

oldSKs = [ SkFile
, SkModule
, SkNamespace
, SkPackage
, SkClass
, SkMethod
, SkProperty
, SkField
, SkConstructor
, SkEnum
, SkInterface
, SkFunction
, SkVariable
, SkConstant
, SkString
, SkNumber
, SkBoolean
, SkArray
]

newSKs = [ SkObject
, SkKey
, SkNull
, SkEnumMember
, SkStruct
, SkEvent
, SkOperator
, SkTypeParameter
]

td = TextDocumentClientCapabilities
(Just sync)
(Just completion)
(Just hover)
(Just signatureHelp)
(Just (ReferencesClientCapabilities dynamicReg))
(Just (DocumentHighlightClientCapabilities dynamicReg))
(Just documentSymbol)
(Just (FormattingClientCapabilities (Just True)))
(Just (RangeFormattingClientCapabilities dynamicReg))
(Just (OnTypeFormattingClientCapabilities dynamicReg))
(Just (DefinitionClientCapabilities dynamicReg))
(since 3 6 (TypeDefinitionClientCapabilities dynamicReg))
(since 3 6 (ImplementationClientCapabilities dynamicReg))
(Just codeAction)
(Just (CodeLensClientCapabilities dynamicReg))
(Just (DocumentLinkClientCapabilities dynamicReg))
(since 3 6 (ColorProviderClientCapabilities dynamicReg))
(Just (RenameClientCapabilities dynamicReg))
(Just (PublishDiagnosticsClientCapabilities (since 3 7 True)))
sync =
SynchronizationTextDocumentClientCapabilities
dynamicReg
(Just True)
(Just True)
(Just True)

completion =
CompletionClientCapabilities
dynamicReg
(Just completionItem)
(since 3 4 completionItemKind)
(since 3 3 True)

completionItem = CompletionItemClientCapabilities
(Just True)
(Just True)
(since 3 3 (List [MkPlainText, MkMarkdown]))
(Just True)
(since 3 9 True)

completionItemKind =
CompletionItemKindClientCapabilities (Just ciKs)

ciKs
| maj >= 3 && min >= 4 = List (oldCiKs ++ newCiKs)
| otherwise = List oldCiKs

oldCiKs = [ CiText
, CiMethod
, CiFunction
, CiConstructor
, CiField
, CiVariable
, CiClass
, CiInterface
, CiModule
, CiProperty
, CiUnit
, CiValue
, CiEnum
, CiKeyword
, CiSnippet
, CiColor
, CiFile
, CiReference
]

newCiKs = [ CiFolder
, CiEnumMember
, CiConstant
, CiStruct
, CiEvent
, CiOperator
, CiTypeParameter
]

hover =
HoverClientCapabilities
dynamicReg
(since 3 3 (List [MkPlainText, MkMarkdown]))

codeAction = CodeActionClientCapabilities
dynamicReg
(since 3 8 (CodeActionLiteralSupport caKs))
caKs = CodeActionKindClientCapabilities
(List [ CodeActionQuickFix
, CodeActionRefactor
, CodeActionRefactorExtract
, CodeActionRefactorInline
, CodeActionRefactorRewrite
, CodeActionSource
, CodeActionSourceOrganizeImports
])

signatureHelp =
SignatureHelpClientCapabilities
dynamicReg
(Just signatureInformation)

signatureInformation =
SignatureInformationClientCapabilities
(Just (List [MkPlainText, MkMarkdown]))

documentSymbol = DocumentSymbolClientCapabilities
dynamicReg
(since 3 4 documentSymbolKind)

documentSymbolKind =
DocumentSymbolKindClientCapabilities
(Just sKs) -- same as workspace symbol kinds

dynamicReg
| maj >= 3 = Just True
| otherwise = Nothing
since x y a
| maj >= x && min >= y = Just a
| otherwise = Nothing

0 comments on commit 9797b27

Please sign in to comment.