From 6cea38f5f3a1ea39add867cf76099eb7a4e824e0 Mon Sep 17 00:00:00 2001 From: stinem1 <54391072+stinem1@users.noreply.github.com> Date: Sun, 25 Aug 2024 11:24:50 +0200 Subject: [PATCH 1/2] Parse windows path --- src/Raise/DiagnosticParser.hs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Raise/DiagnosticParser.hs b/src/Raise/DiagnosticParser.hs index 013f92e..08672de 100644 --- a/src/Raise/DiagnosticParser.hs +++ b/src/Raise/DiagnosticParser.hs @@ -55,7 +55,8 @@ parseDiagnosticLine = T.pack <$> someTill asciiChar newline parseDiagnostic :: Parser Diagnostic parseDiagnostic = do - lookAhead $ oneOf ("./" :: String) -- filepaths start with . (relative) or / (absolute) + lookAhead $ (oneOf ("./" :: String) -- filepaths start with . (relative) or / (absolute) + <|> letterChar <* string ":\\") -- windows filepaths someTill asciiChar (string ".rsl:") row <- max 0 . subtract 1 . read <$> someTill digitChar (char ':') column <- read <$> someTill digitChar (char ':') From 9e29c332253f61d42a6d2c7505d1eb6a33b440df Mon Sep 17 00:00:00 2001 From: stinem1 <54391072+stinem1@users.noreply.github.com> Date: Mon, 26 Aug 2024 20:31:42 +0200 Subject: [PATCH 2/2] Add support for Windows --- package.yaml | 2 ++ rsl-language-server.cabal | 8 +++++++- src/Raise/CodeLens.hs | 1 + src/Raise/DiagnosticParser.hs | 2 -- src/Raise/Diagnostics.hs | 17 +++++++++++------ 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/package.yaml b/package.yaml index 10bc8a1..4230936 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 508368f..65c29c9 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 3fe57d9..fca7b03 100644 --- a/src/Raise/CodeLens.hs +++ b/src/Raise/CodeLens.hs @@ -21,6 +21,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 08672de..5d69a92 100644 --- a/src/Raise/DiagnosticParser.hs +++ b/src/Raise/DiagnosticParser.hs @@ -55,8 +55,6 @@ parseDiagnosticLine = T.pack <$> someTill asciiChar newline parseDiagnostic :: Parser Diagnostic parseDiagnostic = do - lookAhead $ (oneOf ("./" :: String) -- filepaths start with . (relative) or / (absolute) - <|> letterChar <* string ":\\") -- windows filepaths 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 82c07b3..ffd305b 100644 --- a/src/Raise/Diagnostics.hs +++ b/src/Raise/Diagnostics.hs @@ -15,17 +15,22 @@ import qualified Language.LSP.Types as J import qualified Language.LSP.Types.Lens as J import Raise.DiagnosticParser (parseRSLTC) import System.Process (readProcessWithExitCode) +import System.Directory (withCurrentDirectory) +import System.FilePath (takeDirectory, takeFileName) -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