mirror of
https://github.com/unisonweb/unison.git
synced 2024-09-11 10:35:57 +03:00
Bootstrap LSP
This commit is contained in:
parent
ee00a81b46
commit
e17414aa9a
@ -57,6 +57,10 @@ extra-deps:
|
||||
- recover-rtti-0.4.0.0@sha256:2ce1e031ec0e34d736fa45f0149bbd55026f614939dc90ffd14a9c5d24093ff4,4423
|
||||
- lock-file-0.7.0.0@sha256:3ad84b5e454145e1d928063b56abb96db24a99a21b493989520e58fa0ab37b00,4484
|
||||
- http-client-0.7.11
|
||||
- lsp-1.5.0.0
|
||||
- lsp-types-1.5.0.0
|
||||
- text-rope-0.2@sha256:53b9b4cef0b278b9c591cd4ca76543acacf64c9d1bfbc06d0d9a88960446d9a7,2087
|
||||
- co-log-core-0.3.1.0
|
||||
|
||||
ghc-options:
|
||||
# All packages
|
||||
|
@ -116,6 +116,34 @@ packages:
|
||||
sha256: 8372e84e9c710097f4f80f2016ca15a5a0cd7884b8ac5ce70f26b3110f4401bd
|
||||
original:
|
||||
hackage: http-client-0.7.11
|
||||
- completed:
|
||||
hackage: lsp-1.5.0.0@sha256:1ad138526f9177965d4b5b01f9074fe0475636b2c563dcc7036fb6908f8e6189,5382
|
||||
pantry-tree:
|
||||
size: 1551
|
||||
sha256: 87526822a8ffb514d355975bca3a3f5ceb9a19eaf664cbdcde2f866c4d33878c
|
||||
original:
|
||||
hackage: lsp-1.5.0.0
|
||||
- completed:
|
||||
hackage: lsp-types-1.5.0.0@sha256:7ed97bbc9290ad6ffb9b5a8e082226783c710fff9e4ca2df4c578b065997b1ea,4301
|
||||
pantry-tree:
|
||||
size: 4160
|
||||
sha256: e45ef86a4301beb45ae7ec527e69880944a03c2d959cb0a051bf58dd0a5579f4
|
||||
original:
|
||||
hackage: lsp-types-1.5.0.0
|
||||
- completed:
|
||||
hackage: text-rope-0.2@sha256:53b9b4cef0b278b9c591cd4ca76543acacf64c9d1bfbc06d0d9a88960446d9a7,2087
|
||||
pantry-tree:
|
||||
size: 1180
|
||||
sha256: 51b22419f8d9bfd2a8aa3efa16b80a48e4b0c915a1d27fefe5f0b6d2d9e48312
|
||||
original:
|
||||
hackage: text-rope-0.2@sha256:53b9b4cef0b278b9c591cd4ca76543acacf64c9d1bfbc06d0d9a88960446d9a7,2087
|
||||
- completed:
|
||||
hackage: co-log-core-0.3.1.0@sha256:9794bdedd1391decd0e22bdfe2b11abcb42e6cff7a4531e1f8882890828f4e63,3816
|
||||
pantry-tree:
|
||||
size: 584
|
||||
sha256: d4cc089c40c5052ee02f91eafa567e0a239908aabc561dfa6080ba3bfc8c25bd
|
||||
original:
|
||||
hackage: co-log-core-0.3.1.0
|
||||
snapshots:
|
||||
- completed:
|
||||
size: 590100
|
||||
|
@ -36,10 +36,15 @@ dependencies:
|
||||
- ki
|
||||
- lens
|
||||
- lock-file
|
||||
- lsp
|
||||
- lsp-types
|
||||
- megaparsec
|
||||
- memory
|
||||
- mtl
|
||||
- network-uri
|
||||
- network-simple
|
||||
- network
|
||||
- co-log-core
|
||||
- nonempty-containers
|
||||
- open-browser
|
||||
- pretty-simple
|
||||
|
74
unison-cli/src/Unison/LSP.hs
Normal file
74
unison-cli/src/Unison/LSP.hs
Normal file
@ -0,0 +1,74 @@
|
||||
{-# LANGUAGE DataKinds #-}
|
||||
{-# LANGUAGE PolyKinds #-}
|
||||
{-# LANGUAGE RecordWildCards #-}
|
||||
{-# LANGUAGE TypeOperators #-}
|
||||
|
||||
module Unison.LSP where
|
||||
|
||||
import Colog.Core (LogAction (LogAction))
|
||||
import Control.Monad.Reader
|
||||
import Data.Aeson hiding (Options, defaultOptions)
|
||||
import Language.LSP.Server
|
||||
import Language.LSP.Types
|
||||
import Language.LSP.Types.SMethodMap
|
||||
import qualified Network.Simple.TCP as TCP
|
||||
import Network.Socket
|
||||
import System.IO (IOMode (ReadWriteMode))
|
||||
import Unison.Prelude
|
||||
|
||||
newtype Lsp a = Lsp {runLspM :: ReaderT Env (LspM Config) a}
|
||||
deriving newtype (Functor, Applicative, Monad, MonadIO)
|
||||
|
||||
data Env = Env
|
||||
{ context :: LanguageContextEnv Config
|
||||
}
|
||||
|
||||
spawnLsp :: IO ()
|
||||
spawnLsp = TCP.serve (TCP.Host "localhost") "5050" $ \(sock, _sockaddr) -> do
|
||||
sockHandle <- socketToHandle sock ReadWriteMode
|
||||
void $ runServerWithHandles (LogAction print) (LogAction $ liftIO . print) sockHandle sockHandle serverDefinition
|
||||
|
||||
serverDefinition :: ServerDefinition Config
|
||||
serverDefinition =
|
||||
ServerDefinition
|
||||
{ defaultConfig = lspDefaultConfig,
|
||||
onConfigurationChange = lspOnConfigurationChange,
|
||||
doInitialize = lspDoInitialize,
|
||||
staticHandlers = lspStaticHandlers,
|
||||
interpretHandler = lspInterpretHandler,
|
||||
options = lspOptions
|
||||
}
|
||||
|
||||
data Config = Config
|
||||
|
||||
lspOnConfigurationChange :: Config -> Value -> Either Text Config
|
||||
lspOnConfigurationChange _ _ = pure Config
|
||||
|
||||
lspDefaultConfig :: Config
|
||||
lspDefaultConfig = Config
|
||||
|
||||
lspDoInitialize :: LanguageContextEnv Config -> Message 'Initialize -> IO (Either ResponseError Env)
|
||||
lspDoInitialize ctx _ = pure $ Right $ Env ctx
|
||||
|
||||
lspStaticHandlers :: Handlers m
|
||||
lspStaticHandlers =
|
||||
Handlers
|
||||
{ reqHandlers = lspReqHandlers,
|
||||
notHandlers = lspNotHandlers
|
||||
}
|
||||
|
||||
lspReqHandlers :: SMethodMap v
|
||||
lspReqHandlers = mempty
|
||||
|
||||
lspNotHandlers :: SMethodMap v
|
||||
lspNotHandlers = mempty
|
||||
|
||||
lspInterpretHandler :: Env -> Lsp <~> IO
|
||||
lspInterpretHandler env@(Env ctx) =
|
||||
Iso toIO fromIO
|
||||
where
|
||||
toIO (Lsp m) = flip runReaderT ctx . unLspT . flip runReaderT env $ m
|
||||
fromIO m = liftIO m
|
||||
|
||||
lspOptions :: Options
|
||||
lspOptions = defaultOptions
|
@ -60,6 +60,7 @@ library
|
||||
Unison.CommandLine.Main
|
||||
Unison.CommandLine.OutputMessages
|
||||
Unison.CommandLine.Welcome
|
||||
Unison.LSP
|
||||
Unison.Share.Codeserver
|
||||
Unison.Share.Sync
|
||||
Unison.Share.Sync.Types
|
||||
@ -100,6 +101,7 @@ library
|
||||
, base
|
||||
, bytes
|
||||
, bytestring
|
||||
, co-log-core
|
||||
, concurrent-output
|
||||
, configurator
|
||||
, containers >=0.6.3
|
||||
@ -119,9 +121,13 @@ library
|
||||
, ki
|
||||
, lens
|
||||
, lock-file
|
||||
, lsp
|
||||
, lsp-types
|
||||
, megaparsec
|
||||
, memory
|
||||
, mtl
|
||||
, network
|
||||
, network-simple
|
||||
, network-uri
|
||||
, nonempty-containers
|
||||
, open-browser
|
||||
@ -201,6 +207,7 @@ executable cli-integration-tests
|
||||
, base
|
||||
, bytes
|
||||
, bytestring
|
||||
, co-log-core
|
||||
, code-page
|
||||
, concurrent-output
|
||||
, configurator
|
||||
@ -222,9 +229,13 @@ executable cli-integration-tests
|
||||
, ki
|
||||
, lens
|
||||
, lock-file
|
||||
, lsp
|
||||
, lsp-types
|
||||
, megaparsec
|
||||
, memory
|
||||
, mtl
|
||||
, network
|
||||
, network-simple
|
||||
, network-uri
|
||||
, nonempty-containers
|
||||
, open-browser
|
||||
@ -299,6 +310,7 @@ executable transcripts
|
||||
, base
|
||||
, bytes
|
||||
, bytestring
|
||||
, co-log-core
|
||||
, code-page
|
||||
, concurrent-output
|
||||
, configurator
|
||||
@ -320,9 +332,13 @@ executable transcripts
|
||||
, ki
|
||||
, lens
|
||||
, lock-file
|
||||
, lsp
|
||||
, lsp-types
|
||||
, megaparsec
|
||||
, memory
|
||||
, mtl
|
||||
, network
|
||||
, network-simple
|
||||
, network-uri
|
||||
, nonempty-containers
|
||||
, open-browser
|
||||
@ -402,6 +418,7 @@ executable unison
|
||||
, base
|
||||
, bytes
|
||||
, bytestring
|
||||
, co-log-core
|
||||
, code-page
|
||||
, concurrent-output
|
||||
, configurator
|
||||
@ -422,9 +439,13 @@ executable unison
|
||||
, ki
|
||||
, lens
|
||||
, lock-file
|
||||
, lsp
|
||||
, lsp-types
|
||||
, megaparsec
|
||||
, memory
|
||||
, mtl
|
||||
, network
|
||||
, network-simple
|
||||
, network-uri
|
||||
, nonempty-containers
|
||||
, open-browser
|
||||
@ -510,6 +531,7 @@ test-suite cli-tests
|
||||
, base
|
||||
, bytes
|
||||
, bytestring
|
||||
, co-log-core
|
||||
, code-page
|
||||
, concurrent-output
|
||||
, configurator
|
||||
@ -532,9 +554,13 @@ test-suite cli-tests
|
||||
, ki
|
||||
, lens
|
||||
, lock-file
|
||||
, lsp
|
||||
, lsp-types
|
||||
, megaparsec
|
||||
, memory
|
||||
, mtl
|
||||
, network
|
||||
, network-simple
|
||||
, network-uri
|
||||
, nonempty-containers
|
||||
, open-browser
|
||||
|
Loading…
Reference in New Issue
Block a user