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

ElmLS does not send textDocument/publishDiagnostics when entrypoint module is depended by tests and elm-test is installed locally. #728

Closed
IzumiSy opened this issue Jul 17, 2022 · 1 comment

Comments

@IzumiSy
Copy link
Contributor

IzumiSy commented Jul 17, 2022

This only happens with vim-lsp environment. I cannot reproduce this issue on VSCode.
I confirmed the same behavior on VSCode as well. See repro steps.

Expected Behavior

ElmLS sends textDocument/publishDiagnostics to show an error

Current Behavior

No diagnostic appears.

Possible Solution

Possible reason of this issue is that elm-test cannot discover elm binary when it is installed locally, as vim-lsp logging says.

Mon Jul 18 02:21:21 2022:["<---",1,"elm-language-server",{"response":{"method":"window/logMessage","jsonrpc":"2.0","params":{"message":"{\"shortMessage\":\"Command failed with exit code 1: ./node_modules/.bin/elm-test make tests/Tests/Main.elm --report json\",\"command\":\"./node_modules/.bin/elm-test make tests/Tests/Main.elm --report json\",\"escapedCommand\":\"\\\"./node_modules/.bin/elm-test\\\" make \\\"tests/Tests/Main.elm\\\" --report json\",\"exitCode\":1,\"stdout\":\"\",\"stderr\":\"Cannot find elm executable, make sure it is installed.\\n(If elm is not on your path or is called something different the --compiler flag might help.)\\n\",\"failed\":true,\"timedOut\":false,\"isCanceled\":false,\"killed\":false}","type":2}}}]
Mon Jul 18 02:21:21 2022:["<---",1,"elm-language-server",{"response":{"method":"window/logMessage","jsonrpc":"2.0","params":{"message":"Received an invalid json, skipping error.","type":2}}}]
Mon Jul 18 02:21:21 2022:["<---",1,"elm-language-server",{"response":{"method":"window/logMessage","jsonrpc":"2.0","params":{"message":"Received an invalid json, skipping error.","type":2}}}]
Mon Jul 18 02:21:21 2022:["<---",1,"elm-language-server",{"response":{"method":"window/logMessage","jsonrpc":"2.0","params":{"message":"Received an invalid json, skipping error.","type":2}}}]

I have confirmed that using --compiler option when calling elm-test internally for the environment that has installed elm toolchains locally will fix this problem.

My opened PR is #729

Steps to Reproduce (for bugs)

0. Install elm, elm-test locally.

$ npm install -D elm elm-format elm-test

Then, update vim-lsp preference to use them.

let g:lsp_settings = {
\   'elm-language-server': {
\     'initialization_options': {
\       'elmPath': './node_modules/.bin/elm',
\       'elmTestPath': './node_modules/.bin/elm-test'
\     }
\   }
\ }

For VSCode, use the following setting.
スクリーンショット 2022-07-18 3 05 28

1. Create modules.

src/App.elm

module App exposing (main)

import Bar
import Browser
import Html exposing (Html, button, div, text)
import Html.Events exposing (onClick)


type alias Model =
    { count : Int }


initialModel : Model
initialModel =
    { count = 0 }


type Msg
    = Increment
    | Decrement


update : Msg -> Model -> Model
update msg model =
    case msg of
        Increment ->
            { model | count = model.count + 1 }

        Decrement ->
            { model | count = model.count - 1 }


view : Model -> Html Msg
view model =
    div []
        [ button [ onClick Increment ] [ text "+1" ]
        , div [] [ text <| String.fromInt model.count ]
        , button [ onClick Decrement ] [ text "-1" ]
        , div [] [ text Bar.aaa ]
        ]


main : Program () Model Msg
main =
    Browser.sandbox
        { init = initialModel
        , view = view
        , update = update
        }

src/Bar.elm

module Bar exposing (aaa)


aaa : String
aaa =
    "aaa"

tests/Test/Main.elm

module Tests.Main exposing (suite)

import App
import Test


suite : Test.Test
suite =
    let
        _ =
            App.main
    in
    Test.todo "main test"

2. Update Bar.elm to raise a compile error

src/Bar.elm

+ module Nothing.Bar exposing (aaa)
- module Bar exposing (aaa)


aaa : String
aaa =
    "aaa"

Then, no error occurs, even though it must be.

Context

n/a

Your Environment

  • Version used: 2.4.1
  • Editor used: vim + vim-lsp
  • Environment name and version (e.g. node.js 5.4): Node.js v16.15.0
  • Operating System and version: Ubuntu WSL
@IzumiSy IzumiSy changed the title ElmLS does not send textDocument/publishDiagnostics when entrypoint module is depended by tests. ElmLS does not send textDocument/publishDiagnostics when entrypoint module is depended by tests and elm-test is installed locally. Jul 17, 2022
@IzumiSy
Copy link
Contributor Author

IzumiSy commented Jul 18, 2022

Closing by #729

@IzumiSy IzumiSy closed this as completed Jul 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant