Skip to content

Commit a9d8bae

Browse files
committed
[ fix ] Add dummy LSP handlers and release Agda v2.7.0.1 Language Server v3
1 parent 38a7edd commit a9d8bae

File tree

5 files changed

+37
-23
lines changed

5 files changed

+37
-23
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66

7+
## v0.2.7.0.1.3 - 2024-12-5
8+
9+
### Fixed
10+
- Add dummy LSP handlers for `initialized`, `workspace/didChangeConfiguration`, `textDocument/didOpen`, `textDocument/didClose`, `textDocument/didChange`, and `textDocument/didSave` to avoid errors in the client.
11+
712
## v0.2.7.0.1.2 - 2024-12-4
813

914
### Fixed

agda-language-server.cabal

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cabal-version: 1.12
55
-- see: https://github.com/sol/hpack
66

77
name: agda-language-server
8-
version: 0.2.7.0.1.2
8+
version: 0.2.7.0.1.3
99
synopsis: An implementation of language server protocal (LSP) for Agda 2.
1010
description: Please see the README on GitHub at <https://github.com/agda/agda-language-server#readme>
1111
category: Development

package.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: agda-language-server
2-
version: 0.2.7.0.1.2
2+
version: 0.2.7.0.1.3
33
github: "banacorn/agda-language-server"
44
license: MIT
55
author: "Ting-Gian LUA"

src/Options.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ options =
5959
]
6060

6161
usage :: String
62-
usage = "Agda v2.7.0.1 Language Server v2\nUsage: als [Options...]\n"
62+
usage = "Agda v2.7.0.1 Language Server v3\nUsage: als [Options...]\n"
6363

6464
usageAboutAgdaOptions :: String
6565
usageAboutAgdaOptions =

src/Server.hs

+29-20
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ import qualified Data.Aeson as JSON
1616
import Data.Text (pack)
1717
import GHC.IO.IOMode (IOMode (ReadWriteMode))
1818
import Language.LSP.Protocol.Message
19-
import Language.LSP.Protocol.Types
19+
import Language.LSP.Protocol.Types (HoverParams (..), SaveOptions (..), TextDocumentIdentifier (..), TextDocumentSyncKind (..), TextDocumentSyncOptions (..), type (|?) (..))
2020
import Language.LSP.Server hiding (Options)
2121
import qualified Language.LSP.Server hiding (Options)
22+
import qualified Language.LSP.Server as LSP
2223
import Monad
2324
import qualified Network.Simple.TCP as TCP
2425
import Network.Socket (socketToHandle)
@@ -65,13 +66,13 @@ run options = do
6566
{ forward = runLspT ctxEnv . runServerM env,
6667
backward = liftIO
6768
},
68-
options = defaultOptions
69+
options = lspOptions
6970
}
7071

71-
-- lspOptions :: LSP.Options
72-
-- lspOptions = defaultOptions { optTextDocumentSync = Just syncOptions }
72+
lspOptions :: LSP.Options
73+
lspOptions = defaultOptions {optTextDocumentSync = Just syncOptions}
7374

74-
-- -- these `TextDocumentSyncOptions` are essential for receiving notifications from the client
75+
-- these `TextDocumentSyncOptions` are essential for receiving notifications from the client
7576
-- syncOptions :: TextDocumentSyncOptions
7677
-- syncOptions =
7778
-- TextDocumentSyncOptions
@@ -81,13 +82,15 @@ run options = do
8182
-- _willSaveWaitUntil = Just False, -- receive willSave notifications from the client
8283
-- _save = Just $ InR saveOptions
8384
-- }
84-
85-
-- changeOptions :: TextDocumentSyncKind
86-
-- changeOptions = TextDocumentSyncKind_Incremental
87-
88-
-- includes the document content on save, so that we don't have to read it from the disk
89-
-- saveOptions :: SaveOptions
90-
-- saveOptions = SaveOptions (Just True)
85+
syncOptions :: TextDocumentSyncOptions
86+
syncOptions =
87+
TextDocumentSyncOptions
88+
{ _openClose = Just True, -- receive open and close notifications from the client
89+
_change = Just TextDocumentSyncKind_Incremental, -- receive change notifications from the client
90+
_willSave = Just False, -- receive willSave notifications from the client
91+
_willSaveWaitUntil = Just False, -- receive willSave notifications from the client
92+
_save = Just $ InR $ SaveOptions (Just True) -- includes the document content on save, so that we don't have to read it from the disk (not sure if this is still true in lsp 2)
93+
}
9194

9295
-- handlers of the LSP server
9396
handlers :: Handlers (ServerM (LspM Config))
@@ -98,8 +101,8 @@ handlers =
98101
let TRequestMessage _ _i _ params = req
99102
response <- Agda.sendCommand params
100103
responder $ Right response,
101-
-- hover provider
102-
requestHandler hoverMethod $ \req responder -> do
104+
-- `textDocument/hover`
105+
requestHandler SMethod_TextDocumentHover $ \req responder -> do
103106
let TRequestMessage _ _ _ (HoverParams (TextDocumentIdentifier uri) pos _workDone) = req
104107
result <- Handler.onHover uri pos
105108
responder $ Right result,
@@ -108,10 +111,16 @@ handlers =
108111
-- result <- Handler.onHighlight (req ^. (params . textDocument . uri))
109112
-- responder result
110113

111-
-- must provide handler for `initialized` otherwise the client will get nasty error messages
114+
-- `initialized`
112115
notificationHandler SMethod_Initialized $ \_notification -> return (),
113-
-- must provide handler for `workspace/didChangeConfiguration` otherwise the client will get nasty error messages
114-
notificationHandler SMethod_WorkspaceDidChangeConfiguration $ \_notification -> return ()
115-
]
116-
where
117-
hoverMethod = SMethod_TextDocumentHover
116+
-- `workspace/didChangeConfiguration`
117+
notificationHandler SMethod_WorkspaceDidChangeConfiguration $ \_notification -> return (),
118+
-- `textDocument/didOpen`
119+
notificationHandler SMethod_TextDocumentDidOpen $ \_notification -> return (),
120+
-- `textDocument/didClose`
121+
notificationHandler SMethod_TextDocumentDidClose $ \_notification -> return (),
122+
-- `textDocument/didChange`
123+
notificationHandler SMethod_TextDocumentDidChange $ \_notification -> return (),
124+
-- `textDocument/didSave`
125+
notificationHandler SMethod_TextDocumentDidSave $ \_notification -> return ()
126+
]

0 commit comments

Comments
 (0)