Skip to content

Commit fac68b8

Browse files
authored
Merge pull request #502 from haskell/mpj/optional-methods
Fix handling of optional methods
2 parents fa3207d + a9a0b62 commit fac68b8

File tree

6 files changed

+16
-8
lines changed

6 files changed

+16
-8
lines changed

lsp-types/ChangeLog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Revision history for lsp-types
22

3-
## 2.0.0.2
3+
## 2.0.1.0
44

55
* Removed deprecation pragmas from fields, as these cannot currently be avoided.
6+
* Added `isOptionalMethod`, that checks whether a method is optional according to the spec.
67

78
## 2.0.0.1
89

lsp-types/lsp-types.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 3.0
22
name: lsp-types
3-
version: 2.0.0.2
3+
version: 2.0.1.0
44
synopsis:
55
Haskell library for the Microsoft Language Server Protocol, data types
66

lsp-types/src/Language/LSP/Protocol/Message/Method.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module Language.LSP.Protocol.Message.Method where
1414

1515
import Data.Aeson.Types
1616
import Data.Function (on)
17+
import Data.List (isPrefixOf)
1718
import Data.GADT.Compare
1819
import Data.Proxy
1920
import Data.Type.Equality
@@ -29,6 +30,11 @@ import Unsafe.Coerce
2930
-- SomeMethod
3031
---------------
3132

33+
-- | Is this an "optional" method which servers and clients are allowed to ignore?
34+
isOptionalMethod :: SomeMethod -> Bool
35+
-- See https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#dollarRequests
36+
isOptionalMethod m = "$/" `isPrefixOf` someMethodToMethodString m
37+
3238
deriving stock instance Show SomeMethod
3339
instance Eq SomeMethod where
3440
(==) = (==) `on` someMethodToMethodString

lsp/ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Revision history for lsp
22

3+
## 2.0.0.1
4+
5+
* Fix handling of optional methods.
6+
37
## 2.0.0.0
48

59
* Support `lsp-types-2.0.0.0`.

lsp/lsp.cabal

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 2.2
22
name: lsp
3-
version: 2.0.0.0
3+
version: 2.0.0.1
44
synopsis: Haskell library for the Microsoft Language Server Protocol
55
description:
66
An implementation of the types, and basic message server to
@@ -63,7 +63,7 @@ library
6363
, filepath
6464
, hashable
6565
, lens >=4.15.2
66-
, lsp-types ^>=2.0
66+
, lsp-types ^>=2.0.1
6767
, mtl <2.4
6868
, prettyprinter
6969
, random

lsp/src/Language/LSP/Server/Processing.hs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,11 +404,8 @@ handle' logger mAction m msg = do
404404
-- See https://microsoft.github.io/language-server-protocol/specifications/specification-current/#-notifications-and-requests.
405405
reportMissingHandler :: m ()
406406
reportMissingHandler =
407-
let optional = isOptionalNotification m
407+
let optional = isOptionalMethod (SomeMethod m)
408408
in logger <& MissingHandler optional m `WithSeverity` if optional then Warning else Error
409-
isOptionalNotification (SMethod_CustomMethod p)
410-
| "$/" `T.isPrefixOf` T.pack (symbolVal p) = True
411-
isOptionalNotification _ = False
412409

413410
progressCancelHandler :: (m ~ LspM config) => LogAction m (WithSeverity LspProcessingLog) -> TMessage Method_WindowWorkDoneProgressCancel -> m ()
414411
progressCancelHandler logger (TNotificationMessage _ _ (WorkDoneProgressCancelParams tid)) = do

0 commit comments

Comments
 (0)