Skip to content

Commit

Permalink
Fix handling of optional methods
Browse files Browse the repository at this point in the history
Fixes #501
  • Loading branch information
michaelpj committed Jul 7, 2023
1 parent fa3207d commit db90d4b
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 8 deletions.
3 changes: 2 additions & 1 deletion lsp-types/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Revision history for lsp-types

## 2.0.0.2
## 2.0.1.0

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

## 2.0.0.1

Expand Down
2 changes: 1 addition & 1 deletion lsp-types/lsp-types.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.0
name: lsp-types
version: 2.0.0.2
version: 2.0.1.0
synopsis:
Haskell library for the Microsoft Language Server Protocol, data types

Expand Down
6 changes: 6 additions & 0 deletions lsp-types/src/Language/LSP/Protocol/Message/Method.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module Language.LSP.Protocol.Message.Method where

import Data.Aeson.Types
import Data.Function (on)
import Data.List (isPrefixOf)
import Data.GADT.Compare
import Data.Proxy
import Data.Type.Equality
Expand All @@ -29,6 +30,11 @@ import Unsafe.Coerce
-- SomeMethod
---------------

-- | Is this an "optional" method which servers and clients are allowed to ignore?
isOptionalMethod :: SomeMethod -> Bool
-- See https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#dollarRequests
isOptionalMethod m = "$" `isPrefixOf` someMethodToMethodString m

deriving stock instance Show SomeMethod
instance Eq SomeMethod where
(==) = (==) `on` someMethodToMethodString
Expand Down
4 changes: 4 additions & 0 deletions lsp/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Revision history for lsp

## 2.0.0.1

* Fix handling of optional methods.

## 2.0.0.0

* Support `lsp-types-2.0.0.0`.
Expand Down
4 changes: 2 additions & 2 deletions lsp/lsp.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 2.2
name: lsp
version: 2.0.0.0
version: 2.0.0.1
synopsis: Haskell library for the Microsoft Language Server Protocol
description:
An implementation of the types, and basic message server to
Expand Down Expand Up @@ -63,7 +63,7 @@ library
, filepath
, hashable
, lens >=4.15.2
, lsp-types ^>=2.0
, lsp-types ^>=2.0.1
, mtl <2.4
, prettyprinter
, random
Expand Down
5 changes: 1 addition & 4 deletions lsp/src/Language/LSP/Server/Processing.hs
Original file line number Diff line number Diff line change
Expand Up @@ -404,11 +404,8 @@ handle' logger mAction m msg = do
-- See https://microsoft.github.io/language-server-protocol/specifications/specification-current/#-notifications-and-requests.
reportMissingHandler :: m ()
reportMissingHandler =
let optional = isOptionalNotification m
let optional = isOptionalMethod (SomeMethod m)
in logger <& MissingHandler optional m `WithSeverity` if optional then Warning else Error
isOptionalNotification (SMethod_CustomMethod p)
| "$/" `T.isPrefixOf` T.pack (symbolVal p) = True
isOptionalNotification _ = False

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

0 comments on commit db90d4b

Please sign in to comment.