VS Code Language Server crashing

Hi all,

When writing a viewing/writing a benign generator expression in Julia in VSCode, the Language Server crashes repeatedly making developing impossible. I am using the Julia extension 1.6.3 at the moment, with Julia 1.7.2.

I believe I have isolated the offending code below:

 (
        (start:(start + l))
        for start in 1:20 for l in 7:13
            if begin 
                if (start + l) <= 20
                    (start + l) % 2 == 0
                else
                    false
                end
            end
 )

Note that the code is valid Julia, but the language server doesn’t like it for some reason. I’m hypothesising that it is something to do with the linter or syntax highlighting

In the VSCode Output view, the Julia Language Server emits the following:

┌ Error: Some Julia code in the VS Code extension crashed
└ @ Main c:\Users\regan\.vscode\extensions\julialang.language-julia-1.6.3\scripts\error_handler.jl:15
ERROR: offset[2983] > sizeof(content)[2843]
Stacktrace:
 [1] get_position_at(doc::LanguageServer.Document, offset::Int64)
   @ LanguageServer c:\Users\regan\.vscode\extensions\julialang.language-julia-1.6.3\scripts\packages\LanguageServer\src\document.jl:233
 [2] Range
   @ c:\Users\regan\.vscode\extensions\julialang.language-julia-1.6.3\scripts\packages\LanguageServer\src\document.jl:255 [inlined]
 [3] (::LanguageServer.var"#180#181"{Vector{LanguageServer.DocumentHighlight}, LanguageServer.Document})(ref::CSTParser.EXPR, doc1::LanguageServer.Document, o::Int64)
   @ LanguageServer c:\Users\regan\.vscode\extensions\julialang.language-julia-1.6.3\scripts\packages\LanguageServer\src\requests\highlight.jl:10
 [4] for_each_ref(f::LanguageServer.var"#180#181"{Vector{LanguageServer.DocumentHighlight}, LanguageServer.Document}, identifier::CSTParser.EXPR)
   @ LanguageServer c:\Users\regan\.vscode\extensions\julialang.language-julia-1.6.3\scripts\packages\LanguageServer\src\requests\features.jl:271
 [5] textDocument_documentHighlight_request(params::LanguageServer.DocumentHighlightParams, server::LanguageServerInstance, conn::JSONRPC.JSONRPCEndpoint{Base.PipeEndpoint, Base.PipeEndpoint})
   @ LanguageServer c:\Users\regan\.vscode\extensions\julialang.language-julia-1.6.3\scripts\packages\LanguageServer\src\requests\highlight.jl:7
 [6] (::LanguageServer.var"#97#98"{typeof(LanguageServer.textDocument_documentHighlight_request), LanguageServerInstance})(conn::JSONRPC.JSONRPCEndpoint{Base.PipeEndpoint, Base.PipeEndpoint}, params::LanguageServer.DocumentHighlightParams)
   @ LanguageServer c:\Users\regan\.vscode\extensions\julialang.language-julia-1.6.3\scripts\packages\LanguageServer\src\languageserverinstance.jl:251
 [7] dispatch_msg(x::JSONRPC.JSONRPCEndpoint{Base.PipeEndpoint, Base.PipeEndpoint}, dispatcher::JSONRPC.MsgDispatcher, msg::Dict{String, Any})
   @ JSONRPC c:\Users\regan\.vscode\extensions\julialang.language-julia-1.6.3\scripts\packages\JSONRPC\src\typed.jl:67
 [8] run(server::LanguageServerInstance)
   @ LanguageServer c:\Users\regan\.vscode\extensions\julialang.language-julia-1.6.3\scripts\packages\LanguageServer\src\languageserverinstance.jl:365
 [9] top-level scope
   @ c:\Users\regan\.vscode\extensions\julialang.language-julia-1.6.3\scripts\languageserver\main.jl:96

Submitting this as a bug report and a cry for help!

Not confirmed here. But I’ve also seen intermittent crashes of the VS code extension, but more in critical cases like interrupting execution, FWIW…

Edit: is there some opt-in telemetry for this?

I am having a problem with the VS Code Julia language server crashing as well.

This is the file Bugs.jl:

module Bugs

import Base: (==)
export Bug

struct Bug
    data::Vector
    function Bug(list::Vector{T}) where {T<:Integer}
        new(list)
    end
end

Bug(x::T) where {T<:Integer} = Bug([x])

(==)(p::Bug, q::Bug) = p.data == q.data
(==)(a::T, p::Bug) where {T} = p == Bug(a)

end

I start my Julia session inside VS code with Opt-J Opt-O. In the REPL I do this:

julia> include("Bugs.jl")
Main.Bugs

julia> x = Main.Bugs.Bug([1])
Main.Bugs.Bug([1])

This crashes.

I do not see this problem in an ordinary terminal (or in VS Code starting a terminal with Ctrl-BackTic).

If I replace the line

(==)(a::T, p::Bug) where {T} = p == Bug(a)

with

(==)(a::T, p::Bug) where {T <: Integer} = p == Bug(a)

then everything works fine. (I realize the revision is better Julia, but I’m just trying to isolate the crash with as small an example as possible.)