diff --git a/package.yaml b/package.yaml index f422086..bb3e027 100644 --- a/package.yaml +++ b/package.yaml @@ -18,6 +18,8 @@ dependencies: - text - lens - process +- directory +- filepath - megaparsec - optparse-applicative diff --git a/rsl-language-server.cabal b/rsl-language-server.cabal index 43b15b9..9a59d1d 100644 --- a/rsl-language-server.cabal +++ b/rsl-language-server.cabal @@ -1,6 +1,6 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.34.4. +-- This file has been generated from package.yaml by hpack version 0.37.0. -- -- see: https://github.com/sol/hpack @@ -39,6 +39,8 @@ library ghc-options: -flate-dmd-anal -flate-specialise -Wall -Wcompat -Wno-unused-do-bind -Wincomplete-record-updates -Wincomplete-uni-patterns -Wredundant-constraints build-depends: base >=4.7 && <5 + , directory + , filepath , lens , lsp , lsp-types @@ -60,6 +62,8 @@ executable rsl-language-server ghc-options: -flate-dmd-anal -flate-specialise -Wall -Wcompat -Wno-unused-do-bind -Wincomplete-record-updates -Wincomplete-uni-patterns -Wredundant-constraints -O2 -threaded -rtsopts -with-rtsopts=-N build-depends: base >=4.7 && <5 + , directory + , filepath , lens , lsp , lsp-types @@ -85,6 +89,8 @@ test-suite rsl-language-server-test ghc-options: -flate-dmd-anal -flate-specialise -Wall -Wcompat -Wno-unused-do-bind -Wincomplete-record-updates -Wincomplete-uni-patterns -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N -Wno-incomplete-uni-patterns build-depends: base >=4.7 && <5 + , directory + , filepath , hspec , hspec-discover , lens diff --git a/src/Raise/CodeLens.hs b/src/Raise/CodeLens.hs index 844f8bf..dec6309 100644 --- a/src/Raise/CodeLens.hs +++ b/src/Raise/CodeLens.hs @@ -22,6 +22,7 @@ cmdList :: [(T.Text, T.Text)] cmdList = [ ("Typecheck", "raise.typeCheck") , ("Compile to SML", "raise.compileToSML") , ("Run SML", "raise.runSML") + , ("Save Results", "raise.saveResults") ] registerLenses :: LspM () () diff --git a/src/Raise/DiagnosticParser.hs b/src/Raise/DiagnosticParser.hs index f6703fd..c973c60 100644 --- a/src/Raise/DiagnosticParser.hs +++ b/src/Raise/DiagnosticParser.hs @@ -57,7 +57,6 @@ parseDiagnosticLine = T.pack <$> someTill asciiChar newline parseDiagnostic :: Parser Diagnostic parseDiagnostic = do - lookAhead $ oneOf ("./" :: String) -- filepaths start with . (relative) or / (absolute) someTill asciiChar (string ".rsl:") row <- max 0 . subtract 1 . read <$> someTill digitChar (char ':') column <- read <$> someTill digitChar (char ':') diff --git a/src/Raise/Diagnostics.hs b/src/Raise/Diagnostics.hs index ee6d664..bea6e2e 100644 --- a/src/Raise/Diagnostics.hs +++ b/src/Raise/Diagnostics.hs @@ -14,18 +14,23 @@ import qualified Language.LSP.Protocol.Lens as J import qualified Language.LSP.Protocol.Types as J import Language.LSP.Server import Raise.DiagnosticParser (parseRSLTC) +import System.Directory (withCurrentDirectory) +import System.FilePath (takeDirectory, takeFileName) import System.Process (readProcessWithExitCode) -runTool :: String -> [String] -> IO T.Text -runTool tool args = do - (_, stdout, _) <- readProcessWithExitCode tool args "" - pure $ T.pack stdout +runTool :: String -> [String] -> FilePath -> IO T.Text +runTool tool args path = do + let dir = takeDirectory path + file = takeFileName path + withCurrentDirectory dir $ do + (_, stdout, _) <- readProcessWithExitCode tool (args ++ [file]) "" + pure $ T.pack stdout runChecker :: FilePath -> IO T.Text -runChecker path = runTool "rsltc" [path] +runChecker path = runTool "rsltc" [] path runCompiler :: FilePath -> IO T.Text -runCompiler path = runTool "rsltc" ["-m", path] +runCompiler path = runTool "rsltc" ["-m"] path sendDiagnostics :: Bool -> J.NormalizedUri -> FilePath -> LspM () () sendDiagnostics compile fileUri filePath = do