Skip to content

workspace/executeCommand with ExpandFunction can crash server or deletes comments #764

@jwortmann

Description

@jwortmann

LanguageServer v3.1.0

Consider the following file:

f(x) = x + 1

# random comment

Problem 1:
If the 2nd argument for the workspace/executeCommand request with "command": "ExpandFunction" contains an offset value that points to a position outside of an inline function, the server will crash. This happens even for the position of the first character of the function name. Example:

:: --> julia workspace/executeCommand(19): {'command': 'ExpandFunction', 'arguments': ['file:///D:/julia_test/test.jl', 0]}
julia: ERROR: MethodError: no method matching _get_parent_fexpr(::Nothing, ::typeof(LanguageServer.is_single_line_func))
julia: Closest candidates are:
julia: _get_parent_fexpr(!Matched::CSTParser.EXPR, ::Any) at C:\Users\Janos\.julia\packages\LanguageServer\qudfd\src\requests\actions.jl:188
julia: Stacktrace:
julia: [1] expand_inline_func(::Nothing, ::LanguageServerInstance, ::JSONRPC.JSONRPCEndpoint) at C:\Users\Janos\.julia\packages\LanguageServer\qudfd\src\requests\actions.jl:124
julia: [2] workspace_executeCommand_request(::LanguageServer.ExecuteCommandParams, ::LanguageServerInstance, ::JSONRPC.JSONRPCEndpoint) at C:\Users\Janos\.julia\packages\LanguageServer\qudfd\src\requests\actions.jl:42
julia: [3] (::LanguageServer.var"#8#39"{LanguageServerInstance})(::JSONRPC.JSONRPCEndpoint, ::LanguageServer.ExecuteCommandParams) at C:\Users\Janos\.julia\packages\LanguageServer\qudfd\src\languageserverinstance.jl:270
julia: [4] dispatch_msg(::JSONRPC.JSONRPCEndpoint, ::JSONRPC.MsgDispatcher, ::Dict{String,Any}) at C:\Users\Janos\.julia\packages\JSONRPC\nJmHs\src\typed.jl:63
julia: [5] run(::LanguageServerInstance) at C:\Users\Janos\.julia\packages\LanguageServer\qudfd\src\languageserverinstance.jl:305
julia: [6] top-level scope at none:1

Problem 2:
If the subsequent lines contain comments, they will be removed. Example:

:: --> julia workspace/executeCommand(28): {'command': 'ExpandFunction', 'arguments': ['file:///D:/julia_test/test.jl', 5]}
:: <-- julia workspace/applyEdit(b15a33ea-761a-47a9-8732-240dc796fa1a): {'edit': {'changes': None, 'documentChanges': [{'edits': [{'range': {'start': {'line': 0, 'character': 0}, 'end': {'line': 3, 'character': 0}}, 'newText': 'function f(x)\n    x + 1\nend\n'}], 'textDocument': {'version': 145, 'uri': 'file:///d%3A/julia_test/test.jl'}}]}}

I think the line field at end should always be exactly 1 more than at begin, but it is 3 in this example.

In general, consider using Position and Range or even Location for the request arguments instead of using offset values.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions