Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LSP Mk I #3213

Merged
merged 42 commits into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
e17414a
Bootstrap LSP
ChrisPenner Jul 2, 2022
392f763
Working lsp boot-up
ChrisPenner Jul 2, 2022
cda23d0
Wire in VFS
ChrisPenner Jul 2, 2022
79f99e1
Naively receiving completion requests
ChrisPenner Jul 2, 2022
89d1f55
Working completion, hover, etc.
ChrisPenner Jul 2, 2022
276e2cb
Codelens skeleton
ChrisPenner Jul 2, 2022
6ab8459
Don't wait on save
ChrisPenner Jul 7, 2022
82997db
Improve logging
ChrisPenner Jul 7, 2022
efe8803
Docs
ChrisPenner Jul 7, 2022
3fa5e05
Wire typechecking into lsp
ChrisPenner Jul 7, 2022
e3f7f6e
Wire up more parsing
ChrisPenner Jul 7, 2022
38e6c1a
WIP
ChrisPenner Jul 7, 2022
82787bf
WIP
ChrisPenner Jul 7, 2022
5127ce1
WIP - booting up
ChrisPenner Jul 7, 2022
f2f40b4
Type-checking in a loop
ChrisPenner Jul 7, 2022
73a4046
Diagnostics
ChrisPenner Jul 7, 2022
25cf7f7
Add instances
ChrisPenner Jul 7, 2022
c39916b
WIP
ChrisPenner Jul 8, 2022
74b058c
Working _simple_ type errors
ChrisPenner Jul 8, 2022
c116b45
Refactor/reorganize
ChrisPenner Jul 8, 2022
49eb28c
Adding ranges for parse errors
ChrisPenner Jul 8, 2022
632752d
Finish annotating ranges on parse errors
ChrisPenner Jul 8, 2022
dc8628d
Docs
ChrisPenner Jul 8, 2022
9d7e1ec
Merge branch 'trunk' into cp/lsp
ChrisPenner Jul 8, 2022
c78d8b3
Fix formatting in transcripts
ChrisPenner Jul 8, 2022
53ba793
Docs
ChrisPenner Jul 8, 2022
d60855d
Fix tests
ChrisPenner Jul 8, 2022
bcfab5d
Test fixes
ChrisPenner Jul 8, 2022
55cc0c2
README
ChrisPenner Jul 8, 2022
262e2b8
Merge branch 'trunk' into cp/lsp
ChrisPenner Jul 21, 2022
f033635
Merge branch 'trunk' into cp/lsp
ChrisPenner Aug 29, 2022
2ecc993
Fix broken test imports
ChrisPenner Sep 2, 2022
de2d469
Explicit exit from integration tests
ChrisPenner Sep 2, 2022
46ba020
Add helper for socket compatibility on some Windows versions
ChrisPenner Sep 7, 2022
233103d
Use Ki for structured concurrency
ChrisPenner Sep 7, 2022
5539abd
Imports
ChrisPenner Sep 7, 2022
d224a9c
Remove unused codelens module
ChrisPenner Sep 12, 2022
f2ffd25
Disable LSP on windows for now
ChrisPenner Sep 12, 2022
3aa659d
Merge branch 'trunk' into cp/lsp
ChrisPenner Sep 12, 2022
195ecf2
Add note re: LSP on windows
ChrisPenner Sep 12, 2022
41af107
Merge branch 'trunk' into cp/lsp
ChrisPenner Sep 12, 2022
9c029a9
Remove redundant imports
ChrisPenner Sep 12, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 43 additions & 0 deletions docs/language-server.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Unison Language Server

[![asciicast](https://asciinema.org/a/Kwa7NscffA3R8KCHxq1OavRm0.svg)](https://asciinema.org/a/Kwa7NscffA3R8KCHxq1OavRm0)

## Overview

Supported features:

* Show type on hover
* Inline type and parser error messages
* NO autocomplete yet, but soon.

Notes:

* The LSP listens for changes from the UCM it's linked to, so name resolution is dependent on your current UCM path.

## Installation and setup

Currently the only supported configuration is to connect to the LSP via a specified port, not all LSP implementations support this configuration.

By default the LSP is hosted at `127.0.0.1:5757`, but you can change the port using `UNISON_LSP_PORT=1234`.


### NeoVim

Configuration for [coc-nvim](https://github.com/neoclide/coc.nvim), enter the following in the relevant place of your CocConfig

```
"languageserver": {
"unison": {
"filetypes": ["unison"],
"host": "127.0.0.1",
"port": 5757
}
}
```

Note that you'll need to start UCM _before_ you try connecting to it in your editor or your editor might give up.

### VSCode

VSCode doesn't allow customizing LSP implementations without an extension,
Hang tight, one will be available soon!
8 changes: 8 additions & 0 deletions lib/unison-prelude/src/Unison/Debug.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ data DebugFlag
| Migration
| Sqlite
| Sync
| -- Language server
LSP
| -- | Timing how long things take
Timing
deriving (Eq, Ord, Show, Bounded, Enum)
Expand All @@ -48,6 +50,7 @@ debugFlags = case (unsafePerformIO (lookupEnv "UNISON_DEBUG")) of
"MIGRATION" -> pure Migration
"SQLITE" -> pure Sqlite
"SYNC" -> pure Sync
"LSP" -> pure LSP
"TIMING" -> pure Timing
_ -> empty
{-# NOINLINE debugFlags #-}
Expand Down Expand Up @@ -80,6 +83,10 @@ debugSync :: Bool
debugSync = Sync `Set.member` debugFlags
{-# NOINLINE debugSync #-}

debugLSP :: Bool
debugLSP = LSP `Set.member` debugFlags
{-# NOINLINE debugLSP #-}

debugTiming :: Bool
debugTiming = Timing `Set.member` debugFlags
{-# NOINLINE debugTiming #-}
Expand Down Expand Up @@ -131,4 +138,5 @@ shouldDebug = \case
Migration -> debugMigration
Sqlite -> debugSqlite
Sync -> debugSync
LSP -> debugLSP
Timing -> debugTiming
11 changes: 5 additions & 6 deletions parser-typechecker/src/Unison/FileParsers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import Data.Text (unpack)
import qualified Unison.ABT as ABT
import qualified Unison.Blank as Blank
import qualified Unison.Name as Name
import Unison.Names (Names)
import qualified Unison.Names as Names
import qualified Unison.NamesWithHistory as NamesWithHistory
import qualified Unison.Parser as Parser
Expand Down Expand Up @@ -74,14 +73,14 @@ parseAndSynthesizeFile ::
ResultT
(Seq (Note v Ann))
m
(Either Names (UF.TypecheckedUnisonFile v Ann))
(Either (UF.UnisonFile v Ann) (UF.TypecheckedUnisonFile v Ann))
parseAndSynthesizeFile ambient typeLookupf env filePath src = do
when debug $ traceM "parseAndSynthesizeFile"
uf <- Result.fromParsing $ Parsers.parseFile filePath (unpack src) env
let names0 = NamesWithHistory.currentNames (Parser.names env)
(tm, tdnrMap, typeLookup) <- resolveNames typeLookupf names0 uf
let (Result notes' r) = synthesizeFile ambient typeLookup tdnrMap uf tm
tell notes' $> maybe (Left (UF.toNames uf)) Right r
tell notes' $> maybe (Left uf) Right r

type TDNRMap v = Map Typechecker.Name [Typechecker.NamedReference v Ann]

Expand Down Expand Up @@ -221,7 +220,7 @@ synthesizeFile ambient tl fqnsByShortName uf term = do
resolve shortv loc replacement t = case t of
Term.Blank' (Blank.Recorded (Blank.Resolve loc' name))
| loc' == loc && Var.nameStr shortv == name ->
-- loc of replacement already chosen correctly by whatever made the
-- Decision
pure . pure $ replacement
-- loc of replacement already chosen correctly by whatever made the
-- Decision
pure . pure $ replacement
_ -> Nothing
7 changes: 7 additions & 0 deletions parser-typechecker/src/Unison/PrettyPrintEnvDecl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,10 @@ data PrettyPrintEnvDecl = PrettyPrintEnvDecl
suffixifiedPPE :: PrettyPrintEnv
}
deriving (Show)

instance Semigroup PrettyPrintEnvDecl where
PrettyPrintEnvDecl unSuff1 suff1 <> PrettyPrintEnvDecl unSuff2 suff2 =
PrettyPrintEnvDecl (unSuff1 <> unSuff2) (suff1 <> suff2)

instance Monoid PrettyPrintEnvDecl where
mempty = PrettyPrintEnvDecl mempty mempty