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 #2

Open
wants to merge 250 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
250 commits
Select commit Hold shift + click to select a range
e035190
Implement the focus command for limiting externs
purefunctor Jul 30, 2024
b6a443f
Merge remote-tracking branch 'oa/lazy-state-result-#4545' into oa-fork
purefunctor Aug 9, 2024
130593e
Enable CI for oa-fork
purefunctor Aug 12, 2024
3985ae7
Build pre-release on oa-fork
purefunctor Aug 12, 2024
fead96f
Disable CI_PRERELEASE again
purefunctor Aug 12, 2024
dadfaec
Merge branch 'master' of https://github.com/OxfordAbstracts/purescript
roryc89 Sep 9, 2024
48761ab
adds LSP module
roryc89 Sep 13, 2024
99afac3
using reactor
roryc89 Sep 16, 2024
6fdd862
adds simple lsp server
roryc89 Sep 16, 2024
cedeb8a
adds HandlerM and IdeM
roryc89 Sep 17, 2024
ad78e39
use lsp simple
roryc89 Sep 17, 2024
0eeba12
diagnotics sending
roryc89 Sep 17, 2024
daed3ec
fix diagnotics spans
roryc89 Sep 17, 2024
6a489aa
remove duplicate hints
roryc89 Sep 17, 2024
03efe2f
loading all modules
roryc89 Sep 17, 2024
4684502
labels warnings as warnings
roryc89 Sep 17, 2024
fbd65c0
adds Serialise to ErrorMessage
roryc89 Sep 18, 2024
42318c8
remove unused import
roryc89 Sep 18, 2024
d2b8096
adds fix all
roryc89 Sep 18, 2024
b4764c6
start adding workspace edit action
roryc89 Sep 19, 2024
0ed70ef
clean up
roryc89 Sep 19, 2024
e9e2c13
adds FromJSON and ToJSON instances to ErrorMessage
roryc89 Sep 19, 2024
f045071
adds suggestions
roryc89 Sep 19, 2024
0b670a8
Revert "adds FromJSON and ToJSON instances to ErrorMessage"
roryc89 Sep 19, 2024
34a98d7
Revert "adds Serialise to ErrorMessage"
roryc89 Sep 19, 2024
3c00884
add suggested type annotation in correct position
roryc89 Sep 19, 2024
2b8b876
adds file rebuild log
roryc89 Sep 19, 2024
75ee800
start find completions
roryc89 Sep 20, 2024
5ae5a27
hover value showing
roryc89 Sep 22, 2024
461e4c2
types displaying on hover
roryc89 Sep 22, 2024
8ec5801
remove logs
roryc89 Sep 22, 2024
85b1dd5
adds SMethod_TextDocumentDefinition handler but locations not loading
roryc89 Sep 23, 2024
5bbfdf1
add Lsp files
roryc89 Sep 23, 2024
4678bd0
adds start of cache inserts
roryc89 Sep 24, 2024
382d3cd
add serialise to declarations
roryc89 Sep 24, 2024
0ca955e
add Ord instance to Declarations
roryc89 Sep 25, 2024
86e2865
adds rebuild for lsp
roryc89 Sep 25, 2024
d9f749a
first attempt using sqlite
roryc89 Sep 25, 2024
14fbfac
initial lint working
roryc89 Sep 25, 2024
501a245
multiple lints working
roryc89 Sep 25, 2024
888a5bc
buggy hover with filepath added
roryc89 Sep 26, 2024
8893f50
readds build all on start
roryc89 Sep 26, 2024
2621a98
types showing on hover
roryc89 Sep 26, 2024
376197f
hovering works
roryc89 Sep 27, 2024
fc3fa88
IDE: don't force state results (#4546)
roryc89 Sep 29, 2024
287fb33
remove ed instance extern changes
roryc89 Sep 30, 2024
7eff2a9
adds corefn inserting
roryc89 Sep 30, 2024
ce27550
clean up
roryc89 Oct 1, 2024
5e56301
fix queries
roryc89 Oct 1, 2024
b89aa29
remove noisy logs
roryc89 Oct 1, 2024
e8f504d
snake case cols
roryc89 Oct 1, 2024
1b663a8
fixes decoding for core fn queries
roryc89 Oct 1, 2024
bcbf7e6
adds type on hover
roryc89 Oct 1, 2024
7f0c30e
go to definition for by source pos working
roryc89 Oct 1, 2024
7284928
adds environment and decl indexing
roryc89 Oct 1, 2024
707f6c8
adds docs lookup
roryc89 Oct 1, 2024
55c11a3
hover over typeclasses showing kind
roryc89 Oct 2, 2024
0d4a271
get more docs on hover
roryc89 Oct 2, 2024
bfab3d3
type class go to definition working
roryc89 Oct 2, 2024
0238024
adds logs for no found decl
roryc89 Oct 2, 2024
454a1d8
get smallest declarations first
roryc89 Oct 2, 2024
39e1d90
Effect and Unit go to def working
roryc89 Oct 2, 2024
8313d3a
stop unneeded indexing
roryc89 Oct 2, 2024
65e3741
suggestions looking decent
roryc89 Oct 2, 2024
4200bff
start SMethod_CompletionItemResolve
roryc89 Oct 2, 2024
5c2b17b
adds json decl to code complete
roryc89 Oct 2, 2024
6e839aa
use same monad for lsp logic and handlers
roryc89 Oct 3, 2024
02a92ee
move handlers to own module
roryc89 Oct 3, 2024
d115503
better log labels
roryc89 Oct 3, 2024
f82eb75
add reactor to lsp server
roryc89 Oct 3, 2024
d687616
remove comments
roryc89 Oct 3, 2024
1395565
removes diagnostics ref
roryc89 Oct 3, 2024
28d2498
unqualified imports working
roryc89 Oct 3, 2024
7e0a3e6
starts lsp test setup
roryc89 Oct 4, 2024
31bfc8d
remove init state
roryc89 Oct 4, 2024
f41abcd
adds compile custom command to lsp
roryc89 Oct 4, 2024
2683d11
adds compile command and test scaffold
roryc89 Oct 4, 2024
66251b0
only fetch needed externs
roryc89 Oct 4, 2024
55ccd1e
adds time logs
roryc89 Oct 4, 2024
6485911
get definition test passing
roryc89 Oct 5, 2024
e99728f
add lsp desugar
roryc89 Oct 5, 2024
783fc63
adds EnvironmentFn
roryc89 Oct 5, 2024
a1b6de8
start rebuildModuleUsingDbEnv
roryc89 Oct 5, 2024
1b5208f
faster completion
roryc89 Oct 6, 2024
9067b50
use typechecked module
roryc89 Oct 6, 2024
e54dd0c
Async env: start
roryc89 Oct 6, 2024
0366387
Revert "Async env: start"
roryc89 Oct 6, 2024
943d4e8
adds desugarLsp
roryc89 Oct 7, 2024
8ae18c4
get externs from sqlite ordered
roryc89 Oct 7, 2024
9f33f18
adds rebuildModuleWithProvidedEnv
roryc89 Oct 7, 2024
6dfbafe
remove comments
roryc89 Oct 7, 2024
71b25d2
adds perf logs
roryc89 Oct 7, 2024
08a4613
only search in available srcs
roryc89 Oct 7, 2024
17a490d
add ast modules for paths
roryc89 Oct 7, 2024
8a18899
update available srcs on init
roryc89 Oct 7, 2024
f56f1df
add update available srcs function
roryc89 Oct 7, 2024
8c493a3
find definitions is fast
roryc89 Oct 7, 2024
e054cb2
remove perf log
roryc89 Oct 7, 2024
2ca741d
adds cancellation to request
roryc89 Oct 7, 2024
abc381d
search for module names on type
roryc89 Oct 8, 2024
5eaa17f
put each request on a separate thread and catch errors
roryc89 Oct 8, 2024
a800bfc
fix imports length
roryc89 Oct 8, 2024
1003e09
better type displays
roryc89 Oct 8, 2024
6da5ce6
adds method to errors
roryc89 Oct 8, 2024
e6e4d0e
delete comment
roryc89 Oct 8, 2024
0162ad8
remove logs
roryc89 Oct 8, 2024
e45665f
remove unused import
roryc89 Oct 8, 2024
d7cedc9
move to map env
roryc89 Oct 8, 2024
821b355
only load required files into export env
roryc89 Oct 8, 2024
de49453
fast cached rebuilds
roryc89 Oct 8, 2024
2fd6d19
remove open and save rebuild
roryc89 Oct 8, 2024
bda8b52
put handlers in their own modules
roryc89 Oct 9, 2024
84f6468
remove Config var from HandlerM
roryc89 Oct 9, 2024
343428f
adds cancel running requests
roryc89 Oct 9, 2024
82e296e
adds cancellation and error handling
roryc89 Oct 9, 2024
2ae4d0c
use vfs for rebuilding and diagnostics
roryc89 Oct 9, 2024
6ade82c
remove will save sync
roryc89 Oct 9, 2024
fa1537a
remove comma
roryc89 Oct 9, 2024
f31bcf6
easier to read logs
roryc89 Oct 10, 2024
76747e9
prettier logging
roryc89 Oct 10, 2024
b3a5d01
move from glob to instr, remove value selection of ast decls, add Nam…
roryc89 Oct 13, 2024
bc1dab5
fix go to definition for values bugs
roryc89 Oct 13, 2024
d72bae3
fix decl at line
roryc89 Oct 13, 2024
e4cea7f
type definition via ast working
roryc89 Oct 13, 2024
f3d7018
adds type var lookups
roryc89 Oct 13, 2024
77419c8
adds import defintions
roryc89 Oct 13, 2024
3c9f963
adds type for imports without docs
roryc89 Oct 13, 2024
846f147
fix getting last decl
roryc89 Oct 14, 2024
8033aaf
adds hover for local bindings
roryc89 Oct 14, 2024
ee5cae6
adds hover to types using ast
roryc89 Oct 14, 2024
857fc44
clean up
roryc89 Oct 14, 2024
bf5d16b
remove unused queries
roryc89 Oct 14, 2024
5b39f4d
stop storing declaration blobs
roryc89 Oct 14, 2024
3429485
remove end env from cache
roryc89 Oct 14, 2024
4b3de18
adds clear cache commands
roryc89 Oct 14, 2024
8cd5544
remove spaces from commands
roryc89 Oct 14, 2024
bc25b19
removes unnecessary indexing
roryc89 Oct 14, 2024
efa7be9
auto complete working better without manual triggering
roryc89 Oct 14, 2024
eddff6b
adds index custom handler
roryc89 Oct 14, 2024
d821f4f
adds index full
roryc89 Oct 14, 2024
d14e52f
clean up
roryc89 Oct 14, 2024
3b977bc
use purs-lsp-client config section in tests
roryc89 Oct 15, 2024
54e2639
remove env config and use lsp config
roryc89 Oct 15, 2024
2625cd6
remove unused lsp command opts
roryc89 Oct 15, 2024
91b2884
use purescript-lsp config section
roryc89 Oct 15, 2024
d36e71f
remove logs
roryc89 Oct 15, 2024
ae624c2
adds db path log
roryc89 Oct 15, 2024
341f673
canonicalize DB path
roryc89 Oct 15, 2024
e4cd06a
better methods logging
roryc89 Oct 15, 2024
7a967c4
show expression on hover
roryc89 Oct 15, 2024
703a2e5
only update available srcs when needed
roryc89 Oct 16, 2024
aff1581
index ast modules from externs
roryc89 Oct 16, 2024
ae05715
move loglevel to own module and log perf on indexing
roryc89 Oct 16, 2024
f3f0fb8
adds running method debug
roryc89 Oct 16, 2024
69bdc98
make ast declarations unique
roryc89 Oct 16, 2024
8872890
adds hover and go to definition for type class instances
roryc89 Oct 16, 2024
f427864
adds hover and goto def for class members
roryc89 Oct 17, 2024
f54e648
adds monad base control to HandlerM
roryc89 Oct 17, 2024
fe86256
read externs concurrently
roryc89 Oct 17, 2024
b678342
use lifted async for lsp handlers
roryc89 Oct 17, 2024
adabb52
use record syntax for unHandlerM
roryc89 Oct 17, 2024
d415019
adds outputPath to default config
roryc89 Oct 17, 2024
6aeb89c
remove unused arg from codegen
roryc89 Oct 17, 2024
a23e99f
rebuild module even when typechecking fails
roryc89 Oct 17, 2024
249a5a7
use parser to get qualifier name
roryc89 Oct 17, 2024
6f8fac5
rebuild without cache if imports fail
roryc89 Oct 18, 2024
5693acd
rebuild without cache if imports fail
roryc89 Oct 18, 2024
d502cd5
adds constructors to indexing
roryc89 Oct 21, 2024
41e06b2
ctr imports working
roryc89 Oct 21, 2024
8ed7ed3
dont loose import on equal
roryc89 Oct 21, 2024
b0647a6
adds operator search
roryc89 Oct 21, 2024
ef36c07
adds printed types for operators when indexing
roryc89 Oct 21, 2024
72144e3
adds completion kinds
roryc89 Oct 21, 2024
5e77425
names name type not null
roryc89 Oct 21, 2024
e3baba7
insert externs concurrently
roryc89 Oct 21, 2024
52499f5
remove progress indicator as not working
roryc89 Oct 21, 2024
dde90b7
removes module and position from error messages
roryc89 Oct 22, 2024
59f93f1
adds apply all changes quickfix
roryc89 Oct 22, 2024
bb9c5d1
adds purs-tidy formatter
roryc89 Oct 22, 2024
5ff7162
adds import sorting to formatting
roryc89 Oct 22, 2024
c222463
display data and ctr types better
roryc89 Oct 23, 2024
ea57f21
remove logs
roryc89 Oct 23, 2024
d52bd4d
display name types in autocomplete
roryc89 Oct 23, 2024
b8da8a8
check for more possible errors due to cache
roryc89 Oct 23, 2024
5f83c13
dont show value inline for completion
roryc89 Oct 23, 2024
6ca3705
adds everything at types
roryc89 Oct 23, 2024
5b44ffa
hover working for expressions
roryc89 Oct 24, 2024
7512126
adds type value hovering
roryc89 Oct 25, 2024
2d5cba5
adds hover for direct where decls
roryc89 Oct 25, 2024
882b14c
adds inferExprType
roryc89 Oct 26, 2024
c210d86
hover via typed holes working
roryc89 Oct 28, 2024
9c84b89
on hover expr show inference, source type and docs
roryc89 Oct 28, 2024
9b8a65c
remove logs
roryc89 Oct 29, 2024
db4e877
adds binder on hover
roryc89 Oct 29, 2024
68deae6
use lazy state
roryc89 Oct 29, 2024
b3a5086
remove logs
roryc89 Oct 29, 2024
e130e01
adds option to not infer
roryc89 Oct 29, 2024
613a726
bold docs
roryc89 Oct 29, 2024
a8adee5
type kinds on hover fixed
roryc89 Oct 29, 2024
faea44a
fix type syn signatures
roryc89 Oct 30, 2024
be4b701
type class signatures showing
roryc89 Oct 30, 2024
2231c46
get smallest expr
roryc89 Oct 30, 2024
c973284
fixes type alias hovering
roryc89 Oct 30, 2024
a2432af
remove logs
roryc89 Oct 30, 2024
d30b8f9
clean up
roryc89 Oct 30, 2024
9aa5abe
Merge branch 'master' of https://github.com/purescript/purescript int…
roryc89 Oct 31, 2024
0d2d49d
go back to type hole inference
roryc89 Oct 31, 2024
9c07400
adds check state to cache
roryc89 Oct 31, 2024
355c0f9
adds IdeArtifacts
roryc89 Nov 1, 2024
ae6065c
dont track generated expressions
roryc89 Nov 1, 2024
0275285
countUnkownsAndVars
roryc89 Nov 1, 2024
f5596da
use inferBinder instead of inferBinder'
roryc89 Nov 1, 2024
62c2557
revert addIdeExpr
roryc89 Nov 1, 2024
3a7a19d
adds applied types for constructors on hover
roryc89 Nov 2, 2024
8e89356
adds applied types to functions with contrained types
roryc89 Nov 2, 2024
2a5aa80
show substituted types on exprs
roryc89 Nov 4, 2024
202f589
hover showing substituted types
roryc89 Nov 4, 2024
6bc7383
on purs projects hover is running fast but without type substituion
roryc89 Nov 4, 2024
6a93d35
on purs projects hover is running fast but with limited type substitu…
roryc89 Nov 4, 2024
4c19995
decent hover without inferring all expressions
roryc89 Nov 5, 2024
560c68a
remove unneeded ide adding
roryc89 Nov 5, 2024
6682610
adds handling for type synonyms
roryc89 Nov 5, 2024
a7ad826
adds hover on imports
roryc89 Nov 5, 2024
d79bb17
goto def working with artifacts
roryc89 Nov 5, 2024
f2f80d3
remove logs
roryc89 Nov 6, 2024
802325f
use set for artifacts
roryc89 Nov 6, 2024
832e21a
add log for getting diags
roryc89 Nov 6, 2024
cc92ed0
increase cache size
roryc89 Nov 6, 2024
102a9b3
adds functions to cache envs
roryc89 Nov 6, 2024
4a83529
set cache size in mb
roryc89 Nov 6, 2024
05bb2ae
adds export caching
roryc89 Nov 7, 2024
44bd44f
adds in memory caching for environments
roryc89 Nov 7, 2024
b97a48b
fixes ide binders and classnames
roryc89 Nov 7, 2024
13a9209
stop prim hover
roryc89 Nov 7, 2024
c1af4d9
remove hover debug and clean up
roryc89 Nov 7, 2024
8b93fe1
fixes get at position on multi lines
roryc89 Nov 7, 2024
c02599c
fix binder type
roryc89 Nov 7, 2024
e2715bd
adds full rebuild caching
roryc89 Nov 10, 2024
2e373e1
remove test logs
roryc89 Nov 11, 2024
2c29c0c
remove export env from state
roryc89 Nov 12, 2024
2ff0537
adds option to show error module and filepath
roryc89 Nov 12, 2024
dc0e981
better name for diagnostics options
roryc89 Nov 12, 2024
674829e
use force instead of NFData
roryc89 Nov 12, 2024
4d672f0
adds debug-cache-size-evaluated
roryc89 Nov 12, 2024
d2dc3b7
adds refences handler placeholder
roryc89 Nov 15, 2024
48f96dc
adds debug logs for definition
roryc89 Nov 15, 2024
d56fe72
adds format in place
roryc89 Nov 25, 2024
f624114
remove unused import
roryc89 Nov 25, 2024
29b54d2
use longer of ranges
roryc89 Nov 25, 2024
db07957
fix format in place
roryc89 Nov 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: "CI"

on:
push:
branches: [ "master" ]
branches: [ "master", "oa-fork" ]
pull_request:
branches: [ "master" ]
branches: [ "master", "oa-fork" ]
paths:
- .github/workflows/**/*.yml
- app/**/*
Expand Down
164 changes: 88 additions & 76 deletions app/Command/Compile.hs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module Command.Compile (command) where

import Prelude

import Control.Applicative (Alternative(..))
import Control.Applicative (Alternative (..))
import Control.Monad (when)
import Data.Aeson qualified as A
import Data.Bool (bool)
Expand All @@ -13,34 +11,36 @@ import Data.Set qualified as S
import Data.Text qualified as T
import Data.Traversable (for)
import Language.PureScript qualified as P
import Language.PureScript.CST qualified as CST
import Language.PureScript.Errors.JSON (JSONResult(..), toJSONErrors)
import Language.PureScript.Glob (toInputGlobs, PSCGlobs(..), warnFileTypeNotFound)
import Language.PureScript.Make (buildMakeActions, inferForeignModules, runMake)
import Language.PureScript.Compile qualified as P
import Language.PureScript.DB (mkConnection)
import Language.PureScript.Errors.JSON (JSONResult (..), toJSONErrors)
import Language.PureScript.Glob (PSCGlobs (..), toInputGlobs, warnFileTypeNotFound)
import Language.PureScript.Make.Index (initDb)
import Options.Applicative qualified as Opts
import SharedCLI qualified
import System.Console.ANSI qualified as ANSI
import System.Exit (exitSuccess, exitFailure)
import System.Directory (getCurrentDirectory)
import System.Exit (exitFailure, exitSuccess)
import System.IO (hPutStr, stderr, stdout)
import System.IO.UTF8 (readUTF8FilesT)
import Prelude

data PSCMakeOptions = PSCMakeOptions
{ pscmInput :: [FilePath]
, pscmInputFromFile :: Maybe FilePath
, pscmExclude :: [FilePath]
, pscmOutputDir :: FilePath
, pscmOpts :: P.Options
, pscmUsePrefix :: Bool
, pscmJSONErrors :: Bool
{ pscmInput :: [FilePath],
pscmInputFromFile :: Maybe FilePath,
pscmExclude :: [FilePath],
pscmOutputDir :: FilePath,
pscmOpts :: P.Options,
pscmUsePrefix :: Bool,
pscmJSONErrors :: Bool
}

-- | Arguments: verbose, use JSON, warnings, errors
printWarningsAndErrors :: Bool -> Bool -> [(FilePath, T.Text)] -> P.MultipleErrors -> Either P.MultipleErrors a -> IO ()
printWarningsAndErrors verbose False files warnings errors = do
pwd <- getCurrentDirectory
cc <- bool Nothing (Just P.defaultCodeColor) <$> ANSI.hSupportsANSI stdout
let ppeOpts = P.defaultPPEOptions { P.ppeCodeColor = cc, P.ppeFull = verbose, P.ppeRelativeDirectory = pwd, P.ppeFileContents = files }
let ppeOpts = P.defaultPPEOptions {P.ppeCodeColor = cc, P.ppeFull = verbose, P.ppeRelativeDirectory = pwd, P.ppeFileContents = files}
when (P.nonEmpty warnings) $
putStrLn (P.prettyPrintMultipleWarnings ppeOpts warnings)
case errors of
Expand All @@ -50,86 +50,96 @@ printWarningsAndErrors verbose False files warnings errors = do
Right _ -> return ()
printWarningsAndErrors verbose True files warnings errors = do
putStrLn . LBU8.toString . A.encode $
JSONResult (toJSONErrors verbose P.Warning files warnings)
(either (toJSONErrors verbose P.Error files) (const []) errors)
JSONResult
(toJSONErrors verbose P.Warning files warnings)
(either (toJSONErrors verbose P.Error files) (const []) errors)
either (const exitFailure) (const (return ())) errors

compile :: PSCMakeOptions -> IO ()
compile PSCMakeOptions{..} = do
input <- toInputGlobs $ PSCGlobs
{ pscInputGlobs = pscmInput
, pscInputGlobsFromFile = pscmInputFromFile
, pscExcludeGlobs = pscmExclude
, pscWarnFileTypeNotFound = warnFileTypeNotFound "compile"
}
compile PSCMakeOptions {..} = do
input <-
toInputGlobs $
PSCGlobs
{ pscInputGlobs = pscmInput,
pscInputGlobsFromFile = pscmInputFromFile,
pscExcludeGlobs = pscmExclude,
pscWarnFileTypeNotFound = warnFileTypeNotFound "compile"
}
when (null input) $ do
hPutStr stderr $ unlines [ "purs compile: No input files."
, "Usage: For basic information, try the `--help' option."
]
hPutStr stderr $
unlines
[ "purs compile: No input files.",
"Usage: For basic information, try the `--help' option."
]
exitFailure
(_, conn) <- mkConnection pscmOutputDir
initDb conn
moduleFiles <- readUTF8FilesT input
(makeErrors, makeWarnings) <- runMake pscmOpts $ do
ms <- CST.parseModulesFromFiles id moduleFiles
let filePathMap = M.fromList $ map (\(fp, pm) -> (P.getModuleName $ CST.resPartial pm, Right fp)) ms
foreigns <- inferForeignModules filePathMap
let makeActions = buildMakeActions pscmOutputDir filePathMap foreigns pscmUsePrefix
P.make makeActions (map snd ms)
(makeErrors, makeWarnings) <- P.compile pscmOpts moduleFiles conn pscmOutputDir pscmUsePrefix
printWarningsAndErrors (P.optionsVerboseErrors pscmOpts) pscmJSONErrors moduleFiles makeWarnings makeErrors
exitSuccess



outputDirectory :: Opts.Parser FilePath
outputDirectory = Opts.strOption $
Opts.short 'o'
<> Opts.long "output"
<> Opts.value "output"
<> Opts.showDefault
<> Opts.help "The output directory"
outputDirectory =
Opts.strOption $
Opts.short 'o'
<> Opts.long "output"
<> Opts.value "output"
<> Opts.showDefault
<> Opts.help "The output directory"

comments :: Opts.Parser Bool
comments = Opts.switch $
Opts.short 'c'
<> Opts.long "comments"
<> Opts.help "Include comments in the generated code"
comments =
Opts.switch $
Opts.short 'c'
<> Opts.long "comments"
<> Opts.help "Include comments in the generated code"

verboseErrors :: Opts.Parser Bool
verboseErrors = Opts.switch $
Opts.short 'v'
<> Opts.long "verbose-errors"
<> Opts.help "Display verbose error messages"
verboseErrors =
Opts.switch $
Opts.short 'v'
<> Opts.long "verbose-errors"
<> Opts.help "Display verbose error messages"

noPrefix :: Opts.Parser Bool
noPrefix = Opts.switch $
Opts.short 'p'
<> Opts.long "no-prefix"
<> Opts.help "Do not include comment header"
noPrefix =
Opts.switch $
Opts.short 'p'
<> Opts.long "no-prefix"
<> Opts.help "Do not include comment header"

jsonErrors :: Opts.Parser Bool
jsonErrors = Opts.switch $
Opts.long "json-errors"
<> Opts.help "Print errors to stderr as JSON"
jsonErrors =
Opts.switch $
Opts.long "json-errors"
<> Opts.help "Print errors to stderr as JSON"

codegenTargets :: Opts.Parser [P.CodegenTarget]
codegenTargets = Opts.option targetParser $
Opts.short 'g'
<> Opts.long "codegen"
<> Opts.value [P.JS]
<> Opts.help
( "Specifies comma-separated codegen targets to include. "
<> targetsMessage
<> " The default target is 'js', but if this option is used only the targets specified will be used."
)
codegenTargets =
Opts.option targetParser $
Opts.short 'g'
<> Opts.long "codegen"
<> Opts.value [P.JS]
<> Opts.help
( "Specifies comma-separated codegen targets to include. "
<> targetsMessage
<> " The default target is 'js', but if this option is used only the targets specified will be used."
)

targetsMessage :: String
targetsMessage = "Accepted codegen targets are '" <> intercalate "', '" (M.keys P.codegenTargets) <> "'."

targetParser :: Opts.ReadM [P.CodegenTarget]
targetParser =
Opts.str >>= \s ->
for (T.split (== ',') s)
$ maybe (Opts.readerError targetsMessage) pure
. flip M.lookup P.codegenTargets
. T.unpack
. T.strip
for (T.split (== ',') s) $
maybe (Opts.readerError targetsMessage) pure
. flip M.lookup P.codegenTargets
. T.unpack
. T.strip

options :: Opts.Parser P.Options
options =
Expand All @@ -143,13 +153,15 @@ options =
handleTargets ts = S.fromList (if P.JSSourceMap `elem` ts then P.JS : ts else ts)

pscMakeOptions :: Opts.Parser PSCMakeOptions
pscMakeOptions = PSCMakeOptions <$> many SharedCLI.inputFile
<*> SharedCLI.globInputFile
<*> many SharedCLI.excludeFiles
<*> outputDirectory
<*> options
<*> (not <$> noPrefix)
<*> jsonErrors
pscMakeOptions =
PSCMakeOptions
<$> many SharedCLI.inputFile
<*> SharedCLI.globInputFile
<*> many SharedCLI.excludeFiles
<*> outputDirectory
<*> options
<*> (not <$> noPrefix)
<*> jsonErrors

command :: Opts.Parser (IO ())
command = compile <$> (Opts.helper <*> pscMakeOptions)
3 changes: 3 additions & 0 deletions app/Command/Ide.hs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ command = Opts.helper <*> subcommands where
"none" -> LogNone
_ -> LogDefault


-- runM env

startServer :: Network.PortNumber -> IdeEnvironment -> IO ()
startServer port env = Network.withSocketsDo $ do
sock <- listenOnLocalhost port
Expand Down
48 changes: 48 additions & 0 deletions app/Command/Lsp.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
module Command.Lsp (command) where

import Language.PureScript.Lsp as Lsp
import Language.PureScript.Lsp.Types (mkEnv)
import Options.Applicative qualified as Opts
import Protolude
import System.Directory (setCurrentDirectory)

data ServerOptions = ServerOptions
{ _serverDirectory :: Maybe FilePath,
_serverOutputPath :: FilePath
}
deriving (Show)

command :: Opts.Parser (IO ())
command = Opts.helper <*> subcommands
where
subcommands :: Opts.Parser (IO ())
subcommands =
(Opts.subparser . fold)
[ Opts.command
"server"
( Opts.info
(fmap server serverOptions <**> Opts.helper)
(Opts.progDesc "Start a server LSP process")
)
]

server :: ServerOptions -> IO ()
server (ServerOptions dir outputPath) = do
maybe (pure ()) setCurrentDirectory dir
putErrLn $ "Starting server with output path: " <> outputPath
env <- mkEnv outputPath
startServer outputPath env

serverOptions :: Opts.Parser ServerOptions
serverOptions =
ServerOptions
<$> optional (Opts.strOption (Opts.long "directory" `mappend` Opts.short 'd'))
<*> Opts.strOption (Opts.long "output-directory" `mappend` Opts.value "output/")

startServer outputPath env = do
code <- Lsp.main outputPath env
exitWith
( case code of
0 -> ExitSuccess
_ -> ExitFailure code
)
4 changes: 4 additions & 0 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Command.Docs qualified as Docs
import Command.Graph qualified as Graph
import Command.Hierarchy qualified as Hierarchy
import Command.Ide qualified as Ide
import Command.Lsp qualified as Lsp
import Command.Publish qualified as Publish
import Command.REPL qualified as REPL
import Control.Monad (join)
Expand Down Expand Up @@ -76,6 +77,9 @@ main = do
, Opts.command "ide"
(Opts.info Ide.command
(Opts.progDesc "Start or query an IDE server process"))
, Opts.command "lsp"
(Opts.info Lsp.command
(Opts.progDesc "Start or query an IDE server process using the Language Server Protocol"))
, Opts.command "publish"
(Opts.info Publish.command
(Opts.progDesc "Generates documentation packages for upload to Pursuit"))
Expand Down
Loading
Loading