From fa644e23948e62f09a87acda1a569c0242729b07 Mon Sep 17 00:00:00 2001 From: davidanthoff <1036561+davidanthoff@users.noreply.github.com> Date: Tue, 23 Jul 2024 07:49:01 +0000 Subject: [PATCH] Format files using DocumentFormat --- src/extensions/messagedefs.jl | 2 +- src/languageserverinstance.jl | 8 +-- src/multienv.jl | 8 +-- src/protocol/basic.jl | 24 ++++----- src/protocol/completion.jl | 60 +++++++++++----------- src/protocol/configuration.jl | 12 ++--- src/protocol/document.jl | 8 +-- src/protocol/features.jl | 50 +++++++++--------- src/protocol/goto.jl | 2 +- src/protocol/highlight.jl | 8 +-- src/protocol/initialize.jl | 40 +++++++-------- src/protocol/messagedefs.jl | 34 ++++++------- src/protocol/signature.jl | 6 +-- src/protocol/symbols.jl | 52 +++++++++---------- src/requests/actions.jl | 54 ++++++++++---------- src/requests/completions.jl | 48 +++++++++--------- src/requests/features.jl | 54 ++++++++++---------- src/requests/hover.jl | 6 +-- src/requests/init.jl | 20 ++++---- src/requests/misc.jl | 6 +-- src/requests/signatures.jl | 2 +- src/requests/textdocument.jl | 34 ++++++------- src/requests/workspace.jl | 4 +- src/runserver.jl | 8 +-- src/textdocument.jl | 18 +++---- src/utilities.jl | 40 +++++++-------- test/requests/test_actions.jl | 18 +++---- test/requests/test_completions.jl | 3 +- test/requests/test_misc.jl | 2 +- test/test_bruteforce.jl | 8 +-- test/test_document.jl | 2 +- test/test_edit.jl | 2 +- test/test_misc.jl | 2 +- test/test_shared_init_request.jl | 84 +++++++++++++++---------------- 34 files changed, 364 insertions(+), 365 deletions(-) diff --git a/src/extensions/messagedefs.jl b/src/extensions/messagedefs.jl index 8c68eaac..0eb9fdf8 100644 --- a/src/extensions/messagedefs.jl +++ b/src/extensions/messagedefs.jl @@ -1,5 +1,5 @@ const julia_getModuleAt_request_type = JSONRPC.RequestType("julia/getModuleAt", VersionedTextDocumentPositionParams, String) -const julia_getCurrentBlockRange_request_type = JSONRPC.RequestType("julia/getCurrentBlockRange", VersionedTextDocumentPositionParams, Tuple{Position, Position, Position}) +const julia_getCurrentBlockRange_request_type = JSONRPC.RequestType("julia/getCurrentBlockRange", VersionedTextDocumentPositionParams, Tuple{Position,Position,Position}) const julia_getDocAt_request_type = JSONRPC.RequestType("julia/getDocAt", VersionedTextDocumentPositionParams, String) const julia_getDocFromWord_request_type = JSONRPC.RequestType("julia/getDocFromWord", NamedTuple{(:word,),Tuple{String}}, String) const textDocument_publishTests_notification_type = JSONRPC.NotificationType("julia/publishTests", PublishTestsParams) diff --git a/src/languageserverinstance.jl b/src/languageserverinstance.jl index 3ba95f14..c57f479e 100644 --- a/src/languageserverinstance.jl +++ b/src/languageserverinstance.jl @@ -77,7 +77,7 @@ mutable struct LanguageServerInstance # folder. Primarily for projects and manifests outside of the workspace. _extra_tracked_files::Vector{URI} - function LanguageServerInstance(@nospecialize(pipe_in), @nospecialize(pipe_out), env_path="", depot_path="", err_handler=nothing, symserver_store_path=nothing, download=true, symbolcache_upstream = nothing, julia_exe::Union{NamedTuple{(:path,:version),Tuple{String,VersionNumber}},Nothing}=nothing) + function LanguageServerInstance(@nospecialize(pipe_in), @nospecialize(pipe_out), env_path="", depot_path="", err_handler=nothing, symserver_store_path=nothing, download=true, symbolcache_upstream=nothing, julia_exe::Union{NamedTuple{(:path, :version),Tuple{String,VersionNumber}},Nothing}=nothing) new( JSONRPC.JSONRPCEndpoint(pipe_in, pipe_out, err_handler), Set{String}(), @@ -290,7 +290,7 @@ end Run the language `server`. """ -function Base.run(server::LanguageServerInstance; timings = []) +function Base.run(server::LanguageServerInstance; timings=[]) did_show_timer = Ref(false) add_timer_message!(did_show_timer, timings, "LS startup started") @@ -316,7 +316,7 @@ function Base.run(server::LanguageServerInstance; timings = []) if server.err_handler !== nothing server.err_handler(err, bt) else - @warn "LS: An error occurred in the client listener task. This may be normal." exception=(err, bt) + @warn "LS: An error occurred in the client listener task. This may be normal." exception = (err, bt) end finally if isopen(server.combined_msg_queue) @@ -339,7 +339,7 @@ function Base.run(server::LanguageServerInstance; timings = []) if server.err_handler !== nothing server.err_handler(err, bt) else - @error "LS: Queue op failed" ex=(err, bt) + @error "LS: Queue op failed" ex = (err, bt) end finally if isopen(server.combined_msg_queue) diff --git a/src/multienv.jl b/src/multienv.jl index c49cbef6..fbc011ba 100644 --- a/src/multienv.jl +++ b/src/multienv.jl @@ -10,7 +10,7 @@ const project_names = ("JuliaProject.toml", "Project.toml") const manifest_names = ("JuliaManifest.toml", "Manifest.toml") # return nothing or the project file at env -function env_file(env::String, names = project_names)::Union{Nothing,String} +function env_file(env::String, names=project_names)::Union{Nothing,String} if isdir(env) for proj in names project_file = joinpath(env, proj) @@ -49,7 +49,7 @@ function get_env_for_root(doc::Document, server::LanguageServerInstance) (safe_isfile(env_proj_file) && safe_isfile(env_manifest_file)) || return # Find which workspace folder the doc is in. - parent_workspaceFolders = sort(filter(f->startswith(doc._path, f), collect(server.workspaceFolders)), by = length, rev = true) + parent_workspaceFolders = sort(filter(f -> startswith(doc._path, f), collect(server.workspaceFolders)), by=length, rev=true) isempty(parent_workspaceFolders) && return # arbitrarily pick one @@ -94,11 +94,11 @@ function get_env_for_root(doc::Document, server::LanguageServerInstance) msg )) end - @error msg exception=(err, catch_backtrace()) + @error msg exception = (err, catch_backtrace()) end end -function complete_dep_tree(uuid, env_manifest, alldeps = Dict{Base.UUID,Pkg.Types.PackageEntry}()) +function complete_dep_tree(uuid, env_manifest, alldeps=Dict{Base.UUID,Pkg.Types.PackageEntry}()) haskey(alldeps, uuid) && return alldeps alldeps[uuid] = env_manifest[uuid] for dep_uuid in values(alldeps[uuid].deps) diff --git a/src/protocol/basic.jl b/src/protocol/basic.jl index 8c7e16bf..1f3e0619 100644 --- a/src/protocol/basic.jl +++ b/src/protocol/basic.jl @@ -63,14 +63,14 @@ end ############################################################################## # Diagnostics const DiagnosticSeverity = Int -const DiagnosticSeverities = (Error = 1, - Warning = 2, - Information = 3, - Hint = 4) +const DiagnosticSeverities = (Error=1, + Warning=2, + Information=3, + Hint=4) const DiagnosticTag = Int -const DiagnosticTags = (Unnecessary = 1, - Deprecated = 2) +const DiagnosticTags = (Unnecessary=1, + Deprecated=2) @dict_readable struct DiagnosticRelatedInformation <: Outbound location::Location @@ -108,8 +108,8 @@ end ############################################################################## # Markup const MarkupKind = String -const MarkupKinds = (PlainText = "plaintext", - Markdown = "markdown") +const MarkupKinds = (PlainText="plaintext", + Markdown="markdown") mutable struct MarkupContent kind::MarkupKind @@ -130,10 +130,10 @@ Base.hash(x::MarkedString) = hash(x.value) # for unique ############################################################################## # Window const MessageType = Int -const MessageTypes = (Error = 1, - Warning = 2, - Info = 3, - Log = 4) +const MessageTypes = (Error=1, + Warning=2, + Info=3, + Log=4) struct ShowMessageParams <: Outbound type::MessageType diff --git a/src/protocol/completion.jl b/src/protocol/completion.jl index 326b6550..8c158fdf 100644 --- a/src/protocol/completion.jl +++ b/src/protocol/completion.jl @@ -1,41 +1,41 @@ const CompletionItemKind = Int -const CompletionItemKinds = (Text = 1, - Method = 2, - Function = 3, - Constructor = 4, - Field = 5, - Variable = 6, - Class = 7, - Interface = 8, - Module = 9, - Property = 10, - Unit = 11, - Value = 12, - Enum = 13, - Keyword = 14, - Snippet = 15, - Color = 16, - File = 17, - Reference = 18, - Folder = 19, - EnumMember = 20, - Constant = 21, - Struct = 22, - Event = 23, - Operator = 24, - TypeParameter = 25) +const CompletionItemKinds = (Text=1, + Method=2, + Function=3, + Constructor=4, + Field=5, + Variable=6, + Class=7, + Interface=8, + Module=9, + Property=10, + Unit=11, + Value=12, + Enum=13, + Keyword=14, + Snippet=15, + Color=16, + File=17, + Reference=18, + Folder=19, + EnumMember=20, + Constant=21, + Struct=22, + Event=23, + Operator=24, + TypeParameter=25) const CompletionItemTag = Int const CompletionItemTags = (Deprecated = 1) const CompletionTriggerKind = Int -const CompletionTriggerKinds = (Invoked = 1, - TriggerCharacter = 2, - TriggerForIncompleteCompletion = 3) +const CompletionTriggerKinds = (Invoked=1, + TriggerCharacter=2, + TriggerForIncompleteCompletion=3) const InsertTextFormat = Int -const InsertTextFormats = (PlainText = 1, - Snippet = 2) +const InsertTextFormats = (PlainText=1, + Snippet=2) @dict_readable struct CompletionTagClientCapabilities valueSet::Vector{CompletionItemTag} diff --git a/src/protocol/configuration.jl b/src/protocol/configuration.jl index be4e8320..a426f668 100644 --- a/src/protocol/configuration.jl +++ b/src/protocol/configuration.jl @@ -30,14 +30,14 @@ end ############################################################################## # File watching const FileChangeType = Int -const FileChangeTypes = (Created = 1, - Changed = 2, - Deleted = 3) +const FileChangeTypes = (Created=1, + Changed=2, + Deleted=3) const WatchKind = Int -const WatchKinds = (Create = 1, - Change = 2, - Delete = 4) +const WatchKinds = (Create=1, + Change=2, + Delete=4) @dict_readable struct FileEvent diff --git a/src/protocol/document.jl b/src/protocol/document.jl index ccd3c80a..0ddb68a2 100644 --- a/src/protocol/document.jl +++ b/src/protocol/document.jl @@ -76,7 +76,7 @@ end textDocument::TextDocumentItem end -@dict_readable struct TextDocumentContentChangeEvent <: Outbound +@dict_readable struct TextDocumentContentChangeEvent <: Outbound range::Union{Range,Missing} rangeLength::Union{Int,Missing} text::String @@ -97,9 +97,9 @@ end end const TextDocumentSaveReason = Int -const TextDocumentSaveReasons = (Manual = 1, - AfterDelay = 2, - FocusOut = 3) +const TextDocumentSaveReasons = (Manual=1, + AfterDelay=2, + FocusOut=3) @dict_readable struct WillSaveTextDocumentParams textDocument::TextDocumentIdentifier diff --git a/src/protocol/features.jl b/src/protocol/features.jl index b6290a8b..7c3333e8 100644 --- a/src/protocol/features.jl +++ b/src/protocol/features.jl @@ -11,14 +11,14 @@ import Base.== ############################################################################## # Code Action const CodeActionKind = String -const CodeActionKinds = (Empty = "", - QuickFix = "quickfix", - Refactor = "refactor", - RefactorExtract = "refactor.extract", - RefactorInline = "refactor.inline", - RefactorRewrite = "refactor.rewrite", - Source = "source", - SourceOrganizeImports = "source.organizeImports") +const CodeActionKinds = (Empty="", + QuickFix="quickfix", + Refactor="refactor", + RefactorExtract="refactor.extract", + RefactorInline="refactor.inline", + RefactorRewrite="refactor.rewrite", + Source="source", + SourceOrganizeImports="source.organizeImports") @dict_readable struct CodeActionKindCapabilities valueSet::Vector{CodeActionKind} @@ -211,9 +211,9 @@ end ############################################################################## # Folding const FoldingRangeKind = String -const FoldingRangeKinds = (Comment = "comment", - Imports = "imports", - Region = "region") +const FoldingRangeKinds = (Comment="comment", + Imports="imports", + Region="region") @dict_readable struct FoldingRangeClientCapabilities <: Outbound dynamicRegistration::Union{Bool,Missing} @@ -306,8 +306,8 @@ end @dict_readable struct InlayHintRegistrationOptions <: Outbound workDoneToken::Union{Int,String,Missing} # ProgressToken resolveProvider::Bool # InlayHintOptions - id::Union{Missing, String} # StaticRegistrationOptions - documentSelector::Union{Nothing, DocumentSelector} # TextDocumentRegistrationOptions + id::Union{Missing,String} # StaticRegistrationOptions + documentSelector::Union{Nothing,DocumentSelector} # TextDocumentRegistrationOptions end @dict_readable struct InlayHintParams <: Outbound @@ -318,26 +318,26 @@ end @dict_readable struct InlayHintLabelPart <: Outbound value::String - tooltip::Union{Missing, String, MarkupContent} - location::Union{Missing, Location} - command::Union{Missing, Command} + tooltip::Union{Missing,String,MarkupContent} + location::Union{Missing,Location} + command::Union{Missing,Command} end const InlayHintKind = Int const InlayHintKinds = ( - Type = 1, - Parameter = 2 + Type=1, + Parameter=2 ) @dict_readable struct InlayHint <: Outbound position::Position - label::Union{String, Vector{InlayHintLabelPart}} - kind::Union{Missing, InlayHintKind} - textEdits::Union{Missing, Vector{TextEdit}} - tooltip::Union{Missing, String, MarkupContent} - paddingLeft::Union{Missing, Bool} - paddingRight::Union{Missing, Bool} - data::Union{Missing, Any} + label::Union{String,Vector{InlayHintLabelPart}} + kind::Union{Missing,InlayHintKind} + textEdits::Union{Missing,Vector{TextEdit}} + tooltip::Union{Missing,String,MarkupContent} + paddingLeft::Union{Missing,Bool} + paddingRight::Union{Missing,Bool} + data::Union{Missing,Any} end ############################################################################## diff --git a/src/protocol/goto.jl b/src/protocol/goto.jl index f043fd15..3d759dee 100644 --- a/src/protocol/goto.jl +++ b/src/protocol/goto.jl @@ -117,4 +117,4 @@ end workDoneToken::Union{Int,String,Missing} # ProgressToken partialResultToken::Union{Int,String,Missing} # ProgressToken context::ReferenceContext -end \ No newline at end of file +end diff --git a/src/protocol/highlight.jl b/src/protocol/highlight.jl index ef8e8d2a..c2fdd396 100644 --- a/src/protocol/highlight.jl +++ b/src/protocol/highlight.jl @@ -1,7 +1,7 @@ const DocumentHighlightKind = Int -const DocumentHighlightKinds = (Text = 1, - Read = 2, - Write = 3) +const DocumentHighlightKinds = (Text=1, + Read=2, + Write=3) @dict_readable struct DocumentHighlightClientCapabilities <: Outbound dynamicRegistration::Union{Bool,Missing} @@ -26,4 +26,4 @@ end struct DocumentHighlight <: Outbound range::Range kind::Union{DocumentHighlightKind,Missing} -end \ No newline at end of file +end diff --git a/src/protocol/initialize.jl b/src/protocol/initialize.jl index 62d204df..deb9ff6b 100644 --- a/src/protocol/initialize.jl +++ b/src/protocol/initialize.jl @@ -1,15 +1,15 @@ ############################################################################## # From client const FailureHandlingKind = String -const FailureHandlingKinds = (Abort = "abort", - Transactional = "transactional", - TextOnlyTransactional = "textOnlyTransactional", - Undo = "undo") +const FailureHandlingKinds = (Abort="abort", + Transactional="transactional", + TextOnlyTransactional="textOnlyTransactional", + Undo="undo") const ResourceOperationKind = String -const ResourceOperationKinds = (Create = "create", - Rename = "rename", - Delete = "delete") +const ResourceOperationKinds = (Create="create", + Rename="rename", + Delete="delete") @dict_readable struct WorkspaceEditClientCapabilities <: Outbound documentChanges::Union{Bool,Missing} @@ -109,16 +109,16 @@ end # Requires handwritten implementaiton to account for 3-part Unions function InitializeParams(dict::Dict) InitializeParams(dict["processId"], - haskey(dict, "clientInfo") ? InfoParams(dict["clientInfo"]) : missing, - !haskey(dict, "rootPath") ? missing : dict["rootPath"], - # LS specification says this key should always exist, but neovim 0.5.1 doesn't seem to - # send it (seems fixed in neovim 0.6). For now, just assume it might not exist here. - (rootUri = get(dict, "rootUri", nothing); rootUri === nothing) ? nothing : DocumentUri(rootUri), - get(dict, "initializationOptions", missing), - ClientCapabilities(dict["capabilities"]), - haskey(dict, "trace") ? String(dict["trace"]) : missing , - !haskey(dict, "workspaceFolders") ? missing : dict["workspaceFolders"] === nothing ? nothing : WorkspaceFolder.(dict["workspaceFolders"]), - haskey(dict, "workDoneToken") ? dict["workDoneToken"] : missing) + haskey(dict, "clientInfo") ? InfoParams(dict["clientInfo"]) : missing, + !haskey(dict, "rootPath") ? missing : dict["rootPath"], + # LS specification says this key should always exist, but neovim 0.5.1 doesn't seem to + # send it (seems fixed in neovim 0.6). For now, just assume it might not exist here. + (rootUri = get(dict, "rootUri", nothing); rootUri === nothing) ? nothing : DocumentUri(rootUri), + get(dict, "initializationOptions", missing), + ClientCapabilities(dict["capabilities"]), + haskey(dict, "trace") ? String(dict["trace"]) : missing, + !haskey(dict, "workspaceFolders") ? missing : dict["workspaceFolders"] === nothing ? nothing : WorkspaceFolder.(dict["workspaceFolders"]), + haskey(dict, "workDoneToken") ? dict["workDoneToken"] : missing) end ############################################################################## @@ -134,9 +134,9 @@ end struct ColorProviderOptions <: Outbound end const TextDocumentSyncKind = Int -const TextDocumentSyncKinds = (None = 0, - Full = 1, - Incremental = 2) +const TextDocumentSyncKinds = (None=0, + Full=1, + Incremental=2) struct TextDocumentSyncOptions <: Outbound openClose::Union{Bool,Missing} diff --git a/src/protocol/messagedefs.jl b/src/protocol/messagedefs.jl index 4b7a22d7..fc8e595e 100644 --- a/src/protocol/messagedefs.jl +++ b/src/protocol/messagedefs.jl @@ -1,28 +1,28 @@ -const textDocument_codeAction_request_type = JSONRPC.RequestType("textDocument/codeAction", CodeActionParams, Union{Vector{Command}, Vector{CodeAction}, Nothing}) -const textDocument_completion_request_type = JSONRPC.RequestType("textDocument/completion", CompletionParams, Union{CompletionList, Vector{CompletionItem}, Nothing}) -const textDocument_signatureHelp_request_type = JSONRPC.RequestType("textDocument/signatureHelp", TextDocumentPositionParams, Union{SignatureHelp, Nothing}) -const textDocument_definition_request_type = JSONRPC.RequestType("textDocument/definition", TextDocumentPositionParams, Union{Location, Vector{Location}, Vector{LocationLink}, Nothing}) -const textDocument_formatting_request_type = JSONRPC.RequestType("textDocument/formatting", DocumentFormattingParams, Union{Vector{TextEdit}, Nothing}) -const textDocument_range_formatting_request_type = JSONRPC.RequestType("textDocument/rangeFormatting", DocumentRangeFormattingParams, Union{Vector{TextEdit}, Nothing}) -const textDocument_references_request_type = JSONRPC.RequestType("textDocument/references", ReferenceParams, Union{Vector{Location}, Nothing}) -const textDocument_rename_request_type = JSONRPC.RequestType("textDocument/rename", RenameParams, Union{WorkspaceEdit, Nothing}) +const textDocument_codeAction_request_type = JSONRPC.RequestType("textDocument/codeAction", CodeActionParams, Union{Vector{Command},Vector{CodeAction},Nothing}) +const textDocument_completion_request_type = JSONRPC.RequestType("textDocument/completion", CompletionParams, Union{CompletionList,Vector{CompletionItem},Nothing}) +const textDocument_signatureHelp_request_type = JSONRPC.RequestType("textDocument/signatureHelp", TextDocumentPositionParams, Union{SignatureHelp,Nothing}) +const textDocument_definition_request_type = JSONRPC.RequestType("textDocument/definition", TextDocumentPositionParams, Union{Location,Vector{Location},Vector{LocationLink},Nothing}) +const textDocument_formatting_request_type = JSONRPC.RequestType("textDocument/formatting", DocumentFormattingParams, Union{Vector{TextEdit},Nothing}) +const textDocument_range_formatting_request_type = JSONRPC.RequestType("textDocument/rangeFormatting", DocumentRangeFormattingParams, Union{Vector{TextEdit},Nothing}) +const textDocument_references_request_type = JSONRPC.RequestType("textDocument/references", ReferenceParams, Union{Vector{Location},Nothing}) +const textDocument_rename_request_type = JSONRPC.RequestType("textDocument/rename", RenameParams, Union{WorkspaceEdit,Nothing}) const textDocument_prepareRename_request_type = JSONRPC.RequestType("textDocument/prepareRename", PrepareRenameParams, Union{Range,Nothing}) -const textDocument_documentSymbol_request_type = JSONRPC.RequestType("textDocument/documentSymbol", DocumentSymbolParams, Union{Vector{DocumentSymbol}, Vector{SymbolInformation}, Nothing}) -const textDocument_documentHighlight_request_type = JSONRPC.RequestType("textDocument/documentHighlight", DocumentHighlightParams, Union{Vector{DocumentHighlight}, Nothing}) -const textDocument_hover_request_type = JSONRPC.RequestType("textDocument/hover", TextDocumentPositionParams, Union{Hover, Nothing}) +const textDocument_documentSymbol_request_type = JSONRPC.RequestType("textDocument/documentSymbol", DocumentSymbolParams, Union{Vector{DocumentSymbol},Vector{SymbolInformation},Nothing}) +const textDocument_documentHighlight_request_type = JSONRPC.RequestType("textDocument/documentHighlight", DocumentHighlightParams, Union{Vector{DocumentHighlight},Nothing}) +const textDocument_hover_request_type = JSONRPC.RequestType("textDocument/hover", TextDocumentPositionParams, Union{Hover,Nothing}) const textDocument_didOpen_notification_type = JSONRPC.NotificationType("textDocument/didOpen", DidOpenTextDocumentParams) const textDocument_didClose_notification_type = JSONRPC.NotificationType("textDocument/didClose", DidCloseTextDocumentParams) const textDocument_didChange_notification_type = JSONRPC.NotificationType("textDocument/didChange", DidChangeTextDocumentParams) const textDocument_didSave_notification_type = JSONRPC.NotificationType("textDocument/didSave", DidSaveTextDocumentParams) const textDocument_willSave_notification_type = JSONRPC.NotificationType("textDocument/willSave", WillSaveTextDocumentParams) -const textDocument_willSaveWaitUntil_request_type = JSONRPC.RequestType("textDocument/willSaveWaitUntil", WillSaveTextDocumentParams, Union{Vector{TextEdit}, Nothing}) +const textDocument_willSaveWaitUntil_request_type = JSONRPC.RequestType("textDocument/willSaveWaitUntil", WillSaveTextDocumentParams, Union{Vector{TextEdit},Nothing}) const textDocument_publishDiagnostics_notification_type = JSONRPC.NotificationType("textDocument/publishDiagnostics", PublishDiagnosticsParams) -const textDocument_selectionRange_request_type = JSONRPC.RequestType("textDocument/selectionRange", SelectionRangeParams, Union{Vector{SelectionRange}, Nothing}) -const textDocument_documentLink_request_type = JSONRPC.RequestType("textDocument/documentLink", DocumentLinkParams, Union{Vector{DocumentLink}, Nothing}) -const textDocument_inlayHint_request_type = JSONRPC.RequestType("textDocument/inlayHint", InlayHintParams, Union{Vector{InlayHint}, Nothing}) +const textDocument_selectionRange_request_type = JSONRPC.RequestType("textDocument/selectionRange", SelectionRangeParams, Union{Vector{SelectionRange},Nothing}) +const textDocument_documentLink_request_type = JSONRPC.RequestType("textDocument/documentLink", DocumentLinkParams, Union{Vector{DocumentLink},Nothing}) +const textDocument_inlayHint_request_type = JSONRPC.RequestType("textDocument/inlayHint", InlayHintParams, Union{Vector{InlayHint},Nothing}) const workspace_executeCommand_request_type = JSONRPC.RequestType("workspace/executeCommand", ExecuteCommandParams, Any) -const workspace_symbol_request_type = JSONRPC.RequestType("workspace/symbol", WorkspaceSymbolParams, Union{Vector{SymbolInformation}, Nothing}) +const workspace_symbol_request_type = JSONRPC.RequestType("workspace/symbol", WorkspaceSymbolParams, Union{Vector{SymbolInformation},Nothing}) const workspace_didChangeWatchedFiles_notification_type = JSONRPC.NotificationType("workspace/didChangeWatchedFiles", DidChangeWatchedFilesParams) const workspace_didChangeConfiguration_notification_type = JSONRPC.NotificationType("workspace/didChangeConfiguration", DidChangeConfigurationParams) const workspace_didChangeWorkspaceFolders_notification_type = JSONRPC.NotificationType("workspace/didChangeWorkspaceFolders", DidChangeWorkspaceFoldersParams) @@ -44,7 +44,7 @@ const setTraceNotification_notification_type = JSONRPC.NotificationType("\$/setT const window_workDoneProgress_create_request_type = JSONRPC.RequestType("window/workDoneProgress/create", WorkDoneProgressCreateParams, Nothing) const window_showMessage_notification_type = JSONRPC.NotificationType("window/showMessage", ShowMessageParams) -const window_showMessage_request_type = JSONRPC.RequestType("window/showMessageRequest", ShowMessageRequestParams, Union{MessageActionItem, Nothing}) +const window_showMessage_request_type = JSONRPC.RequestType("window/showMessageRequest", ShowMessageRequestParams, Union{MessageActionItem,Nothing}) const progress_notification_type = JSONRPC.NotificationType("\$/progress", ProgressParams) diff --git a/src/protocol/signature.jl b/src/protocol/signature.jl index 2eac2fe7..9450c55a 100644 --- a/src/protocol/signature.jl +++ b/src/protocol/signature.jl @@ -14,9 +14,9 @@ end end const SignatureHelpTriggerKind = Int -const SignatureHelpTriggerKinds = (Invoked = 1, - TriggerCharacter = 2, - ContentChange = 3) +const SignatureHelpTriggerKinds = (Invoked=1, + TriggerCharacter=2, + ContentChange=3) struct SignatureHelpOptions <: Outbound triggerCharacters::Union{Vector{String},Missing} diff --git a/src/protocol/symbols.jl b/src/protocol/symbols.jl index ec3ceb0f..d34ea262 100644 --- a/src/protocol/symbols.jl +++ b/src/protocol/symbols.jl @@ -1,30 +1,30 @@ const SymbolKind = Int -const SymbolKinds = (File = 1, - Module = 2, - Namespace = 3, - Package = 4, - Class = 5, - Method = 6, - Property = 7, - Field = 8, - Constructor = 9, - Enum = 10, - Interface = 11, - Function = 12, - Variable = 13, - Constant = 14, - String = 15, - Number = 16, - Boolean = 17, - Array = 18, - Object = 19, - Key = 20, - Null = 21, - EnumMember = 22, - Struct = 23, - Event = 24, - Operator = 25, - TypeParameter = 26) +const SymbolKinds = (File=1, + Module=2, + Namespace=3, + Package=4, + Class=5, + Method=6, + Property=7, + Field=8, + Constructor=9, + Enum=10, + Interface=11, + Function=12, + Variable=13, + Constant=14, + String=15, + Number=16, + Boolean=17, + Array=18, + Object=19, + Key=20, + Null=21, + EnumMember=22, + Struct=23, + Event=24, + Operator=25, + TypeParameter=26) @dict_readable struct SymbolKindCapabilities <: Outbound valueSet::Union{Vector{SymbolKind},Missing} diff --git a/src/requests/actions.jl b/src/requests/actions.jl index c6aa2a7e..b35b392a 100644 --- a/src/requests/actions.jl +++ b/src/requests/actions.jl @@ -12,7 +12,7 @@ function client_support_action_kind(s::LanguageServerInstance, _::CodeActionKind s.clientCapabilities.textDocument !== missing && s.clientCapabilities.textDocument.codeAction !== missing && s.clientCapabilities.textDocument.codeAction.codeActionLiteralSupport !== missing - s.clientCapabilities.textDocument.codeAction.codeActionLiteralSupport.codeActionKind !== missing + s.clientCapabilities.textDocument.codeAction.codeActionLiteralSupport.codeActionKind !== missing # From the spec of CodeActionKind (https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#codeActionClientCapabilities): # # The code action kind values the client supports. When this @@ -32,9 +32,9 @@ function client_preferred_support(s::LanguageServerInstance)::Bool s.clientCapabilities.textDocument !== missing && s.clientCapabilities.textDocument.codeAction !== missing && s.clientCapabilities.textDocument.codeAction.isPreferredSupport !== missing - return s.clientCapabilities.textDocument.codeAction.isPreferredSupport - else - return false + return s.clientCapabilities.textDocument.codeAction.isPreferredSupport + else + return false end end @@ -56,7 +56,7 @@ function textDocument_codeAction_request(params::CodeActionParams, server::Langu if sa.when(x, params) kind = sa.kind if sa.kind !== missing && sa.kind == CodeActionKinds.SourceOrganizeImports && - server.clientInfo !== missing && occursin("code", lowercase(server.clientInfo.name)) + server.clientInfo !== missing && occursin("code", lowercase(server.clientInfo.name)) # SourceOrganizeImports doesn't show up in the VS Code UI, so make this a # RefactorRewrite instead kind = CodeActionKinds.RefactorRewrite @@ -163,16 +163,16 @@ function expand_inline_func(x, server, conn) if headof(body) == :block && length(body) == 1 file, offset = get_file_loc(func) tde = TextDocumentEdit(VersionedTextDocumentIdentifier(get_uri(file), get_version(file)), TextEdit[ - TextEdit(Range(file, offset .+ (0:func.span)), string("function ", get_text(file)[offset .+ (1:sig.span)], "\n ", get_text(file)[offset + sig.fullspan + op.fullspan .+ (1:body.span)], "\nend")) + TextEdit(Range(file, offset .+ (0:func.span)), string("function ", get_text(file)[offset.+(1:sig.span)], "\n ", get_text(file)[offset+sig.fullspan+op.fullspan.+(1:body.span)], "\nend")) ]) JSONRPC.send(conn, workspace_applyEdit_request_type, ApplyWorkspaceEditParams(missing, WorkspaceEdit(missing, TextDocumentEdit[tde]))) elseif (headof(body) === :begin || CSTParser.isbracketed(body)) && - headof(body.args[1]) === :block && length(body.args[1]) > 0 + headof(body.args[1]) === :block && length(body.args[1]) > 0 file, offset = get_file_loc(func) - newtext = string("function ", get_text(file)[offset .+ (1:sig.span)]) + newtext = string("function ", get_text(file)[offset.+(1:sig.span)]) blockoffset = offset + sig.fullspan + op.fullspan + body.trivia[1].fullspan for i = 1:length(body.args[1].args) - newtext = string(newtext, "\n ", get_text(file)[blockoffset .+ (1:body.args[1].args[i].span)]) + newtext = string(newtext, "\n ", get_text(file)[blockoffset.+(1:body.args[1].args[i].span)]) blockoffset += body.args[1].args[i].fullspan end newtext = string(newtext, "\nend") @@ -203,9 +203,9 @@ function get_next_line_offset(x) # get next line after using_stmt insertpos = -1 line_offsets = get_line_offsets(get_text_document(file)) - for i = 1:length(line_offsets) - 1 - if line_offsets[i] < offset + x.span <= line_offsets[i + 1] - insertpos = line_offsets[i + 1] + for i = 1:length(line_offsets)-1 + if line_offsets[i] < offset + x.span <= line_offsets[i+1] + insertpos = line_offsets[i+1] end end return insertpos @@ -321,12 +321,12 @@ function remove_farg_name(x, server, conn) file, offset = get_file_loc(x1) if CSTParser.isdeclaration(x1) tde = TextDocumentEdit(VersionedTextDocumentIdentifier(get_uri(file), get_version(file)), TextEdit[ - TextEdit(Range(file, offset .+ (0:x1.args[1].fullspan)), "") - ]) + TextEdit(Range(file, offset .+ (0:x1.args[1].fullspan)), "") + ]) else tde = TextDocumentEdit(VersionedTextDocumentIdentifier(get_uri(file), get_version(file)), TextEdit[ - TextEdit(Range(file, offset .+ (0:x1.fullspan)), "_") - ]) + TextEdit(Range(file, offset .+ (0:x1.fullspan)), "_") + ]) end JSONRPC.send(conn, workspace_applyEdit_request_type, ApplyWorkspaceEditParams(missing, WorkspaceEdit(missing, TextDocumentEdit[tde]))) end @@ -335,8 +335,8 @@ function remove_unused_assignment_name(x, _, conn) x1 = StaticLint.get_parent_fexpr(x, x -> StaticLint.haserror(x) && StaticLint.errorof(x) == StaticLint.UnusedBinding && x isa EXPR && x.head === :IDENTIFIER) file, offset = get_file_loc(x1) tde = TextDocumentEdit(VersionedTextDocumentIdentifier(get_uri(file), get_version(file)), TextEdit[ - TextEdit(Range(file, offset .+ (0:x1.span)), "_") - ]) + TextEdit(Range(file, offset .+ (0:x1.span)), "_") + ]) JSONRPC.send(conn, workspace_applyEdit_request_type, ApplyWorkspaceEditParams(missing, WorkspaceEdit(missing, TextDocumentEdit[tde]))) end @@ -363,8 +363,8 @@ function in_same_workspace_folder(server::LanguageServerInstance, file1::URI, fi for ws in server.workspaceFolders if startswith(file1_str, ws) && startswith(file2_str, ws) - return true - end + return true + end end return false end @@ -381,7 +381,7 @@ function identify_short_identifier(server::LanguageServerInstance, file::Documen return first(candidate_identifiers) else numerous = iszero(length(candidate_identifiers)) ? "no" : "multiple" - @warn "Found $numerous candidates for the SPDX header from open files, falling back to LICENSE" Candidates=candidate_identifiers + @warn "Found $numerous candidates for the SPDX header from open files, falling back to LICENSE" Candidates = candidate_identifiers end # Fallback to looking for a license file in the same workspace folder @@ -414,7 +414,7 @@ function identify_short_identifier(server::LanguageServerInstance, file::Documen return "EUPL-$version" end - @warn "A license was found, but could not be identified! Consider adding its licence identifier once to a file manually so that LanguageServer.jl can find it automatically next time." Location=first(candidate_files) + @warn "A license was found, but could not be identified! Consider adding its licence identifier once to a file manually so that LanguageServer.jl can find it automatically next time." Location = first(candidate_files) return nothing end @@ -609,7 +609,7 @@ function convert_to_raw(x, _, conn) end function convert_from_raw(x, _, conn) - is_string_literal(x; inraw = true) || return + is_string_literal(x; inraw=true) || return xparent = x.parent file, offset = get_file_loc(xparent) quotes = headof(x) === :TRIPLESTRING ? "\"\"" : "" # TODO: raw""" not supported yet @@ -651,7 +651,7 @@ function add_docstring_template(x, _, conn) file, func_offset = get_file_loc(func) sig = func.args[1] _, sig_offset = get_file_loc(sig) - docstr = "\"\"\"\n " * get_text(file)[sig_offset .+ (1:sig.span)] * "\n\nTBW\n\"\"\"\n" + docstr = "\"\"\"\n " * get_text(file)[sig_offset.+(1:sig.span)] * "\n\nTBW\n\"\"\"\n" tde = TextDocumentEdit(VersionedTextDocumentIdentifier(get_uri(file), get_version(file)), TextEdit[ TextEdit(Range(file, func_offset:func_offset), docstr) ]) @@ -661,8 +661,8 @@ end function is_in_docstring_for_function(x::EXPR, _) return CSTParser.isstringliteral(x) && x.parent isa EXPR && headof(x.parent) === :macrocall && - length(x.parent.args) == 4 && x.parent.args[1] isa EXPR && - headof(x.parent.args[1]) === :globalrefdoc && CSTParser.defines_function(x.parent.args[4]) + length(x.parent.args) == 4 && x.parent.args[1] isa EXPR && + headof(x.parent.args[1]) === :globalrefdoc && CSTParser.defines_function(x.parent.args[4]) end function update_docstring_sig(x, _, conn) @@ -681,7 +681,7 @@ function update_docstring_sig(x, _, conn) # New signature in the code sig = func.args[1] _, sig_offset = get_file_loc(sig) - sig_str = get_text(file)[sig_offset .+ (1:sig.span)] + sig_str = get_text(file)[sig_offset.+(1:sig.span)] # Heuristic for finding a signature in the current docstring reg = r"\A .*$"m if (m = match(reg, valof(docstr_expr)); m !== nothing) diff --git a/src/requests/completions.jl b/src/requests/completions.jl index ebc4de99..d6e6f50d 100644 --- a/src/requests/completions.jl +++ b/src/requests/completions.jl @@ -6,7 +6,7 @@ struct CompletionState offset::Int completions::Dict{String,CompletionItem} range::Range - x::Union{Nothing, EXPR} + x::Union{Nothing,EXPR} doc::Document server::LanguageServerInstance using_stmts::Dict{String,Any} @@ -48,7 +48,7 @@ function textDocument_completion_request(params::CompletionParams, server::Langu CompletionState(offset, Dict{String,CompletionItem}(), rng, x, doc, server, using_stmts) end - ppt, pt, t, is_at_end = get_partial_completion(state) + ppt, pt, t, is_at_end = get_partial_completion(state) if pt isa CSTParser.Tokens.Token && pt.kind == CSTParser.Tokenize.Tokens.BACKSLASH latex_completions(string("\\", CSTParser.Tokenize.untokenize(t)), state) @@ -58,9 +58,9 @@ function textDocument_completion_request(params::CompletionParams, server::Langu partial = is_latex_comp(t.val, state.offset - t.startbyte) !isempty(partial) && latex_completions(partial, state) elseif t isa CSTParser.Tokens.Token && (t.kind in (CSTParser.Tokenize.Tokens.STRING, - CSTParser.Tokenize.Tokens.TRIPLE_STRING, - CSTParser.Tokenize.Tokens.CMD, - CSTParser.Tokenize.Tokens.TRIPLE_CMD)) + CSTParser.Tokenize.Tokens.TRIPLE_STRING, + CSTParser.Tokenize.Tokens.CMD, + CSTParser.Tokenize.Tokens.TRIPLE_CMD)) string_completion(t, state) elseif state.x isa EXPR && is_in_import_statement(state.x) import_completions(ppt, pt, t, is_at_end, state.x, state) @@ -158,7 +158,7 @@ const snippet_completions = Dict{String,String}( "try" => "try\n\t\$0\ncatch\nend", "using" => "using ", "while" => "while \$1\n\t\$0\nend" - ) +) function texteditfor(state::CompletionState, partial, n) @@ -282,9 +282,9 @@ end function is_rebinding_of_module(x) x isa EXPR && refof(x).type === StaticLint.CoreTypes.Module && # binding is a Module - refof(x).val isa EXPR && CSTParser.isassignment(refof(x).val) && # binding expr is an assignment - StaticLint.hasref(refof(x).val.args[2]) && refof(refof(x).val.args[2]).type === StaticLint.CoreTypes.Module && - refof(refof(x).val.args[2]).val isa EXPR && CSTParser.defines_module(refof(refof(x).val.args[2]).val)# double check the rhs points to a module + refof(x).val isa EXPR && CSTParser.isassignment(refof(x).val) && # binding expr is an assignment + StaticLint.hasref(refof(x).val.args[2]) && refof(refof(x).val.args[2]).type === StaticLint.CoreTypes.Module && + refof(refof(x).val.args[2]).val isa EXPR && CSTParser.defines_module(refof(refof(x).val.args[2]).val)# double check the rhs points to a module end function _get_dot_completion(px, spartial, state::CompletionState) end @@ -359,7 +359,7 @@ end function string_completion(t, state::CompletionState) path_completion(t, state) # Need to adjust things for quotation marks - if t.kind in (CSTParser.Tokenize.Tokens.STRING,CSTParser.Tokenize.Tokens.CMD) + if t.kind in (CSTParser.Tokenize.Tokens.STRING, CSTParser.Tokenize.Tokens.CMD) t.startbyte + 1 < state.offset <= t.endbyte || return relative_offset = state.offset - t.startbyte - 1 content = t.val[2:prevind(t.val, lastindex(t.val))] @@ -390,18 +390,18 @@ function is_latex_comp_char(u) # latex completions. # from: UInt8.(sort!(unique(prod([k[2:end] for (k,_) in Iterators.flatten((REPL.REPLCompletions.latex_symbols, REPL.REPLCompletions.emoji_symbols))])))) u === 0x21 || - u === 0x28 || - u === 0x29 || - u === 0x2b || - u === 0x2d || - u === 0x2f || - 0x30 <= u <= 0x39 || - u === 0x3a || - u === 0x3d || - 0x41 <= u <= 0x5a || - u === 0x5e || - u === 0x5f || - 0x61 <= u <= 0x7a + u === 0x28 || + u === 0x29 || + u === 0x2b || + u === 0x2d || + u === 0x2f || + 0x30 <= u <= 0x39 || + u === 0x3a || + u === 0x3d || + 0x41 <= u <= 0x5a || + u === 0x5e || + u === 0x5f || + 0x61 <= u <= 0x7a end function path_completion(t, state::CompletionState) @@ -426,7 +426,7 @@ function path_completion(t, state::CompletionState) if isdir(joinpath(dir, f)) f = string(f, "/") end - rng1 = Range(state.doc, state.offset - sizeof(partial):state.offset) + rng1 = Range(state.doc, state.offset-sizeof(partial):state.offset) add_completion_item(state, CompletionItem(f, CompletionItemKinds.File, f, TextEdit(rng1, f))) catch err isa(err, Base.IOError) || isa(err, Base.SystemError) || rethrow() @@ -447,7 +447,7 @@ function import_completions(ppt, pt, t, is_at_end, x, state::CompletionState) import_root = get_import_root(import_statement) if (t.kind == CSTParser.Tokens.WHITESPACE && pt.kind ∈ (CSTParser.Tokens.USING, CSTParser.Tokens.IMPORT, CSTParser.Tokens.IMPORTALL, CSTParser.Tokens.COMMA, CSTParser.Tokens.COLON)) || - (t.kind in (CSTParser.Tokens.COMMA, CSTParser.Tokens.COLON)) + (t.kind in (CSTParser.Tokens.COMMA, CSTParser.Tokens.COLON)) # no partial, no dot if import_root !== nothing && refof(import_root) isa SymbolServer.ModuleStore for (n, m) in refof(import_root).vals diff --git a/src/requests/features.jl b/src/requests/features.jl index 9d232b64..59f87764 100644 --- a/src/requests/features.jl +++ b/src/requests/features.jl @@ -129,10 +129,10 @@ function get_juliaformatter_config(doc, server) path = get_path(doc) # search through workspace for a `.JuliaFormatter.toml` - workspace_dirs = sort(filter(f -> startswith(path, f), collect(server.workspaceFolders)), by = length, rev = true) + workspace_dirs = sort(filter(f -> startswith(path, f), collect(server.workspaceFolders)), by=length, rev=true) config_path = length(workspace_dirs) > 0 ? - search_file(JuliaFormatter.CONFIG_FILE_NAME, path, workspace_dirs[1]) : - nothing + search_file(JuliaFormatter.CONFIG_FILE_NAME, path, workspace_dirs[1]) : + nothing config_path === nothing && return nothing @@ -142,13 +142,13 @@ end function default_juliaformatter_config(params) return ( - indent = params.options.tabSize, - annotate_untyped_fields_with_any = false, - join_lines_based_on_source = true, - trailing_comma = nothing, - margin = 10_000, - always_for_in = nothing, - whitespace_in_kwargs = false + indent=params.options.tabSize, + annotate_untyped_fields_with_any=false, + join_lines_based_on_source=true, + trailing_comma=nothing, + margin=10_000, + always_for_in=nothing, + whitespace_in_kwargs=false ) end @@ -298,9 +298,9 @@ end is_valid_binding_name(name) = false function is_valid_binding_name(name::EXPR) (headof(name) === :IDENTIFIER && valof(name) isa String && !isempty(valof(name))) || - CSTParser.isoperator(name) || - (headof(name) === :NONSTDIDENTIFIER && length(name.args) == 2 && valof(name.args[2]) isa String && !isempty(valof(name.args[2]))) || - is_callable_object_binding(name) + CSTParser.isoperator(name) || + (headof(name) === :NONSTDIDENTIFIER && length(name.args) == 2 && valof(name.args[2]) isa String && !isempty(valof(name.args[2]))) || + is_callable_object_binding(name) end function get_name_of_binding(name::EXPR) if headof(name) === :IDENTIFIER @@ -342,7 +342,7 @@ function collect_document_symbols(x::EXPR, server::LanguageServerInstance, doc, ) if bindingof(x) !== nothing - b = bindingof(x) + b = bindingof(x) if b.val isa EXPR && is_valid_binding_name(b.name) ds = DocumentSymbol( get_name_of_binding(b.name), # name @@ -535,7 +535,7 @@ function _score(needle::Symbol, haystack::Symbol) end # TODO: handle documentation resolving properly, respect how Documenter handles that function julia_getDocFromWord_request(params::NamedTuple{(:word,),Tuple{String}}, server::LanguageServerInstance, conn) - matches = Pair{Float64, String}[] + matches = Pair{Float64,String}[] needle = Symbol(params.word) nfound = 0 traverse_by_name(getsymbols(getenv(server))) do sym, val @@ -552,7 +552,7 @@ function julia_getDocFromWord_request(params::NamedTuple{(:word,),Tuple{String}} if isempty(matches) return "No results found." else - return join(map(x -> x.second, sort!(unique!(matches), by = x -> x.first)[1:min(end, 25)]), "\n---\n") + return join(map(x -> x.second, sort!(unique!(matches), by=x -> x.first)[1:min(end, 25)]), "\n---\n") end end @@ -564,8 +564,8 @@ function textDocument_selectionRange_request(params::SelectionRangeParams, serve get_selection_range_of_expr(x) end return ret isa Vector{SelectionRange} ? - ret : - nothing + ret : + nothing end # Just returns a selection for each parent EXPR, should be more selective @@ -631,20 +631,20 @@ end function collect_inlay_hints(x::EXPR, server::LanguageServerInstance, doc, start, stop, pos=0, hints=InlayHint[]) if x isa EXPR && parentof(x) isa EXPR && - CSTParser.iscall(parentof(x)) && - !( - parentof(parentof(x)) isa EXPR && - CSTParser.defines_function(parentof(parentof(x))) - ) && - parentof(x).args[1] != x # function calls + CSTParser.iscall(parentof(x)) && + !( + parentof(parentof(x)) isa EXPR && + CSTParser.defines_function(parentof(parentof(x))) + ) && + parentof(x).args[1] != x # function calls maybe_hint = get_inlay_parameter_hints(x, server, doc, pos) if maybe_hint !== nothing push!(hints, maybe_hint) end elseif x isa EXPR && parentof(x) isa EXPR && - CSTParser.isassignment(parentof(x)) && - parentof(x).args[1] == x && - StaticLint.hasbinding(x) # assignment + CSTParser.isassignment(parentof(x)) && + parentof(x).args[1] == x && + StaticLint.hasbinding(x) # assignment if server.inlay_hints_variable_types typ = _completion_type(StaticLint.bindingof(x)) if typ !== missing diff --git a/src/requests/hover.jl b/src/requests/hover.jl index d5172c41..b8c82f74 100644 --- a/src/requests/hover.jl +++ b/src/requests/hover.jl @@ -27,7 +27,7 @@ function get_hover(x::EXPR, documentation::String, server, expr, env) return documentation end -function get_tooltip(b::StaticLint.Binding, documentation::String, server, expr = nothing, env = nothing; show_definition = false) +function get_tooltip(b::StaticLint.Binding, documentation::String, server, expr=nothing, env=nothing; show_definition=false) if b.val isa StaticLint.Binding documentation = get_hover(b.val, documentation, server, expr, env) elseif b.val isa EXPR @@ -76,7 +76,7 @@ function get_tooltip(b::StaticLint.Binding, documentation::String, server, expr end get_hover(b::StaticLint.Binding, documentation::String, server, expr, env) = - get_tooltip(b, documentation, server, expr, env; show_definition = true) + get_tooltip(b, documentation, server, expr, env; show_definition=true) get_typed_definition(b) = _completion_type(b) get_typed_definition(b::StaticLint.Binding) = @@ -215,7 +215,7 @@ function get_preceding_docs(expr::EXPR, documentation) end end -ensure_ends_with(s, c = "\n") = endswith(s, c) ? s : string(s, c) +ensure_ends_with(s, c="\n") = endswith(s, c) ? s : string(s, c) binding_has_preceding_docs(b::StaticLint.Binding) = expr_has_preceding_docs(b.val) diff --git a/src/requests/init.jl b/src/requests/init.jl index c10857d6..1cc5ca17 100644 --- a/src/requests/init.jl +++ b/src/requests/init.jl @@ -79,11 +79,11 @@ end function load_rootpath(path) try return isdir(path) && - hasreadperm(path) && - path != "" && - path != homedir() && - !isjuliabasedir(path) && - !has_too_many_files(path) + hasreadperm(path) && + path != "" && + path != homedir() && + !isjuliabasedir(path) && + !has_too_many_files(path) catch err is_walkdir_error(err) || rethrow() return false @@ -147,7 +147,7 @@ function initialize_request(params::InitializeParams, server::LanguageServerInst if !(params.rootUri isa Nothing) push!(server.workspaceFolders, uri2filepath(params.rootUri)) elseif !(params.rootPath isa Nothing) - push!(server.workspaceFolders, params.rootPath) + push!(server.workspaceFolders, params.rootPath) end elseif (params.workspaceFolders !== nothing) & (params.workspaceFolders !== missing) for wksp in params.workspaceFolders @@ -171,9 +171,9 @@ function initialize_request(params::InitializeParams, server::LanguageServerInst end if !ismissing(params.capabilities.workspace) && - !ismissing(params.capabilities.workspace.didChangeConfiguration) && - !ismissing(params.capabilities.workspace.didChangeConfiguration.dynamicRegistration) && - params.capabilities.workspace.didChangeConfiguration.dynamicRegistration + !ismissing(params.capabilities.workspace.didChangeConfiguration) && + !ismissing(params.capabilities.workspace.didChangeConfiguration.dynamicRegistration) && + params.capabilities.workspace.didChangeConfiguration.dynamicRegistration server.clientcapability_workspace_didChangeConfiguration = true end @@ -225,7 +225,7 @@ function initialized_notification(params::InitializedParams, server::LanguageSer uri = filepath2uri(file_full_path) if isfile(file_full_path) # Only add again if outside of the workspace folders - if all(i->!startswith(file_full_path, i), server.workspaceFolders) + if all(i -> !startswith(file_full_path, i), server.workspaceFolders) if haskey(server._files_from_disc, uri) error("This should not happen") end diff --git a/src/requests/misc.jl b/src/requests/misc.jl index 054f3b18..8f6aabf5 100644 --- a/src/requests/misc.jl +++ b/src/requests/misc.jl @@ -35,7 +35,7 @@ function julia_getCurrentBlockRange_request(tdpp::VersionedTextDocumentPositionP thisline, _ = get_position_from_offset(doc, loc + a.span) if tdpp.position.line > thisline || headof(a) === :NOTHING loc += a.fullspan - a = x[i + 1] + a = x[i+1] end end end @@ -89,13 +89,13 @@ function julia_activateenvironment_notification(params::NamedTuple{(:envPath,),T uri = filepath2uri(file_full_path) if isfile(file_full_path) # Only add again if outside of the workspace folders - if all(i->!startswith(file_full_path, i), server.workspaceFolders) + if all(i -> !startswith(file_full_path, i), server.workspaceFolders) if haskey(server._files_from_disc, uri) error("This should not happen") end text_file = JuliaWorkspaces.read_text_file_from_uri(uri, return_nothing_on_io_error=true) - text_file===nothing || continue + text_file === nothing || continue server._files_from_disc[uri] = text_file diff --git a/src/requests/signatures.jl b/src/requests/signatures.jl index 93e716e7..bbf80062 100644 --- a/src/requests/signatures.jl +++ b/src/requests/signatures.jl @@ -61,7 +61,7 @@ function get_signatures(b::StaticLint.Binding, tls::StaticLint.Scope, sigs::Vect end end -function get_signatures(b::T, tls::StaticLint.Scope, sigs::Vector{SignatureInformation}, env) where T <: Union{SymbolServer.FunctionStore,SymbolServer.DataTypeStore} +function get_signatures(b::T, tls::StaticLint.Scope, sigs::Vector{SignatureInformation}, env) where T<:Union{SymbolServer.FunctionStore,SymbolServer.DataTypeStore} StaticLint.iterate_over_ss_methods(b, tls, env, function (m) push!(sigs, SignatureInformation(string(m), "", (a -> ParameterInformation(string(a[1]), string(a[2]))).(m.sig))) return false diff --git a/src/requests/textdocument.jl b/src/requests/textdocument.jl index 754d02a1..244b0f76 100644 --- a/src/requests/textdocument.jl +++ b/src/requests/textdocument.jl @@ -106,11 +106,11 @@ end comp(x, y) = x == y function comp(x::CSTParser.EXPR, y::CSTParser.EXPR) comp(x.head, y.head) && - x.span == y.span && - x.fullspan == y.fullspan && - x.val == y.val && - length(x) == length(y) && - all(comp(x[i], y[i]) for i = 1:length(x)) + x.span == y.span && + x.fullspan == y.fullspan && + x.val == y.val && + length(x) == length(y) && + all(comp(x[i], y[i]) for i = 1:length(x)) end function textDocument_didChange_notification(params::DidChangeTextDocumentParams, server::LanguageServerInstance, conn) @@ -134,7 +134,7 @@ function textDocument_didChange_notification(params::DidChangeTextDocumentParams error("This should not happen") end - if server._open_file_versions[uri]>params.textDocument.version + if server._open_file_versions[uri] > params.textDocument.version error("Outdated version: server $(server._open_file_versions[uri]) params $(params.textDocument.version)") end @@ -149,15 +149,15 @@ function textDocument_didChange_notification(params::DidChangeTextDocumentParams lint!(doc, server) elseif get_language_id(doc) == "julia" cst0, cst1 = getcst(doc), CSTParser.parse(get_text(doc), true) - r1, r2, r3 = CSTParser.minimal_reparse(s0, get_text(doc), cst0, cst1, inds = true) - for i in setdiff(1:length(cst0.args), r1 , r3) # clean meta from deleted expr + r1, r2, r3 = CSTParser.minimal_reparse(s0, get_text(doc), cst0, cst1, inds=true) + for i in setdiff(1:length(cst0.args), r1, r3) # clean meta from deleted expr StaticLint.clear_meta(cst0[i]) end setcst(doc, EXPR(cst0.head, EXPR[cst0.args[r1]; cst1.args[r2]; cst0.args[r3]], nothing)) sizeof(get_text(doc)) == getcst(doc).fullspan || @error "CST does not match input string length." headof(doc.cst) === :file ? set_doc(doc.cst, doc) : @info "headof(doc) isn't :file for $(doc._path)" - target_exprs = getcst(doc).args[last(r1) .+ (1:length(r2))] + target_exprs = getcst(doc).args[last(r1).+(1:length(r2))] semantic_pass(getroot(doc), target_exprs) lint!(doc, server) end @@ -209,7 +209,7 @@ function mark_errors(doc, out=Diagnostic[]) while line < nlines seek(io, line_offsets[line]) char = 0 - while line_offsets[line] <= offset < line_offsets[line + 1] + while line_offsets[line] <= offset < line_offsets[line+1] while offset > position(io) c = read(io, Char) if UInt32(c) >= 0x010000 @@ -265,8 +265,8 @@ Is this diagnostic reliant on the current environment being accurately represent """ function is_diag_dependent_on_env(diag::Diagnostic) startswith(diag.message, "Missing reference: ") || - startswith(diag.message, "Possible method call error") || - startswith(diag.message, "An imported") + startswith(diag.message, "Possible method call error") || + startswith(diag.message, "An imported") end function print_substitute_line(io::IO, line) @@ -410,11 +410,11 @@ function publish_diagnostics(uris::Vector{URI}, server, conn, source) st = JuliaWorkspaces.get_text_file(server.workspace, uri).content append!(diags, Diagnostic( Range(st, i.range), - if i.severity==:error + if i.severity == :error DiagnosticSeverities.Error - elseif i.severity==:warning + elseif i.severity == :warning DiagnosticSeverities.Warning - elseif i.severity==:info + elseif i.severity == :info DiagnosticSeverities.Information else error("Unknown severity $(i.severity)") @@ -429,7 +429,7 @@ function publish_diagnostics(uris::Vector{URI}, server, conn, source) end end - for (uri,diags) in diagnostics + for (uri, diags) in diagnostics version = get(server._open_file_versions, uri, missing) params = PublishDiagnosticsParams(uri, version, diags) JSONRPC.send(conn, textDocument_publishDiagnostics_notification_type, params) @@ -445,7 +445,7 @@ function publish_tests(server::LanguageServerInstance) st = JuliaWorkspaces.get_text_file(server.workspace, uri).content testitems = TestItemDetail[TestItemDetail(i.id, i.name, Range(st, i.range), st.content[i.code_range], Range(st, i.code_range), i.option_default_imports, string.(i.option_tags), string.(i.option_setup)) for i in testitems_results.testitems] - testsetups= TestSetupDetail[TestSetupDetail(string(i.name), string(i.kind), Range(st, i.range), st.content[i.code_range], Range(st, i.code_range), ) for i in testitems_results.testsetups] + testsetups = TestSetupDetail[TestSetupDetail(string(i.name), string(i.kind), Range(st, i.range), st.content[i.code_range], Range(st, i.code_range),) for i in testitems_results.testsetups] testerrors = TestErrorDetail[TestErrorDetail(te.id, te.name, Range(st, te.range), te.message) for te in testitems_results.testerrors] version = get(server._open_file_versions, uri, missing) diff --git a/src/requests/workspace.jl b/src/requests/workspace.jl index 473fdda5..b7d319de 100644 --- a/src/requests/workspace.jl +++ b/src/requests/workspace.jl @@ -7,7 +7,7 @@ function workspace_didChangeWatchedFiles_notification(params::DidChangeWatchedFi for change in params.changes uri = change.uri - uri.scheme=="file" || continue + uri.scheme == "file" || continue if change.type == FileChangeTypes.Created || change.type == FileChangeTypes.Changed text_file = JuliaWorkspaces.read_text_file_from_uri(uri, return_nothing_on_io_error=true) @@ -157,7 +157,7 @@ end function gc_files_from_workspace(server::LanguageServerInstance) for uri in keys(server._files_from_disc) - if any(i->startswith(string(uri), i), string.(filepath2uri.(server.workspaceFolders))) + if any(i -> startswith(string(uri), i), string.(filepath2uri.(server.workspaceFolders))) continue end diff --git a/src/runserver.jl b/src/runserver.jl index 55dc40cb..39e808d0 100644 --- a/src/runserver.jl +++ b/src/runserver.jl @@ -35,15 +35,15 @@ julia --project=/path/to/LanguageServer.jl \\ ``` """ function runserver(@nospecialize(pipe_in)=stdin, pipe_out=stdout, env_path=choose_env(), - depot_path="", err_handler=nothing, symserver_store_path=nothing) + depot_path="", err_handler=nothing, symserver_store_path=nothing) server = LanguageServerInstance(pipe_in, pipe_out, env_path, depot_path, - err_handler, symserver_store_path) + err_handler, symserver_store_path) run(server) end function choose_env() maybe_dirname = x -> x !== nothing ? dirname(x) : nothing something(get(ARGS, 1, nothing), # 1. path passed explicitly - maybe_dirname(Base.current_project(pwd())), # 2. parent project of pwd() - maybe_dirname(Base.load_path_expand("@v#.#"))) # 3. default "global" env + maybe_dirname(Base.current_project(pwd())), # 2. parent project of pwd() + maybe_dirname(Base.load_path_expand("@v#.#"))) # 3. default "global" env end diff --git a/src/textdocument.jl b/src/textdocument.jl index 9f275c49..9a27e8f2 100644 --- a/src/textdocument.jl +++ b/src/textdocument.jl @@ -6,7 +6,7 @@ struct TextDocument _line_indices::Union{Nothing,Vector{Int}} _language_id::String - function TextDocument(uri::URI, text::AbstractString, version::Int, lid = nothing) + function TextDocument(uri::URI, text::AbstractString, version::Int, lid=nothing) # TODO Remove this check eventually occursin('\0', text) && throw(LSInvalidFile("Tried to set a text with an embedded NULL as the document content.")) @@ -61,9 +61,9 @@ function index_at(doc::TextDocument, line::Integer, character::Integer, forgivin throw(LSOffsetError("index_at crashed. More diagnostics:\nline=$line\nline_indices='$line_indices'")) end - line_index = line_indices[line + 1] + line_index = line_indices[line+1] - next_line_index = line + 1 < length(line_indices) ? line_indices[line + 2] : nextind(text, lastindex(text)) + next_line_index = line + 1 < length(line_indices) ? line_indices[line+2] : nextind(text, lastindex(text)) pos = line_index @@ -133,7 +133,7 @@ function _compute_line_indices(text) while ind <= lastindex(text) c = text[ind] if c == '\n' || c == '\r' - if c == '\r' && ind + 1 <= lastindex(text) && text[ind + 1] == '\n' + if c == '\r' && ind + 1 <= lastindex(text) && text[ind+1] == '\n' ind += 1 end push!(line_indices, ind + 1) @@ -176,12 +176,12 @@ function _get_line_of(doc::TextDocument, offset::Integer) else line = 1 while line < nlines - if line_offsets[line] <= offset < line_offsets[line + 1] + if line_offsets[line] <= offset < line_offsets[line+1] break end line += 1 end -end + end return line, line_offsets[line] end @@ -196,7 +196,7 @@ function _compute_line_offsets(text) while ind <= lastindex(text) c = text[ind] nl = c == '\n' || c == '\r' - if c == '\r' && ind + 1 <= lastindex(text) && text[ind + 1] == '\n' + if c == '\r' && ind + 1 <= lastindex(text) && text[ind+1] == '\n' ind += 1 end nl && push!(line_offsets, ind) @@ -245,7 +245,7 @@ function get_position_from_offset(doc::TextDocument, offset::Integer) c = read(io, Char) character += 1 if UInt32(c) >= 0x010000 - character += 1 + character += 1 end end close(io) @@ -266,5 +266,5 @@ function Range(st::JuliaWorkspaces.SourceText, rng::UnitRange) start_l, start_c = JuliaWorkspaces.position_at(st, first(rng)) end_l, end_c = JuliaWorkspaces.position_at(st, last(rng)) - return Range(start_l-1, start_c-1, end_l-1, end_c-1) + return Range(start_l - 1, start_c - 1, end_l - 1, end_c - 1) end diff --git a/src/utilities.jl b/src/utilities.jl index 73487f04..f7dfdd1f 100644 --- a/src/utilities.jl +++ b/src/utilities.jl @@ -20,7 +20,7 @@ end # lookup # ------ -traverse_by_name(f, cache = SymbolServer.stdlibs) = traverse_store!.(f, values(cache)) +traverse_by_name(f, cache=SymbolServer.stdlibs) = traverse_store!.(f, values(cache)) traverse_store!(_, _) = return traverse_store!(f, store::SymbolServer.EnvStore) = traverse_store!.(f, values(store)) @@ -79,9 +79,9 @@ function remove_workspace_files(root, server) get_open_in_editor(doc) && continue # If the file is in any other workspace folder, don't delete it any(folder -> startswith(fpath, folder), server.workspaceFolders) && continue - deletedocument!(server, uri) - end + deletedocument!(server, uri) end +end # TODO DA removed this, make sure it really isn't needed @@ -94,7 +94,7 @@ function remove_workspace_files(root, server) # end function _offset_unitrange(r::UnitRange{Int}, first=true) - return r.start - 1:r.stop + return r.start-1:r.stop end function get_toks(doc, offset) @@ -202,7 +202,7 @@ end get_inner_expr(doc::Document, rng::Range) = get_inner_expr(getcst(doc), get_offset(doc, rng)) # full (not only trivia) expr containing rng, modulo whitespace -function get_inner_expr(x, rng::UnitRange{Int}, pos=0, pos_span = 0) +function get_inner_expr(x, rng::UnitRange{Int}, pos=0, pos_span=0) if all(pos .> rng) return nothing end @@ -242,8 +242,8 @@ function get_expr1(x, offset, pos=0) if offset == pos if i == 1 return get_expr1(arg, offset, pos) - elseif headof(x[i - 1]) === :IDENTIFIER - return get_expr1(x[i - 1], offset, pos) + elseif headof(x[i-1]) === :IDENTIFIER + return get_expr1(x[i-1], offset, pos) else return get_expr1(arg, offset, pos) end @@ -254,8 +254,8 @@ function get_expr1(x, offset, pos=0) if offset == pos if i == 1 return get_expr1(arg, offset, pos) - elseif headof(x[i - 1]) === :IDENTIFIER - return get_expr1(x[i - 1], offset, pos) + elseif headof(x[i-1]) === :IDENTIFIER + return get_expr1(x[i-1], offset, pos) else return get_expr1(arg, offset, pos) end @@ -317,7 +317,7 @@ if VERSION < v"1.1" || Sys.iswindows() && VERSION < v"1.3" end return out end - _path_separator = "\\" + _path_separator = "\\" _path_separator_re = r"[/\\]+" function _pathsep(paths::AbstractString...) for path in paths @@ -330,11 +330,11 @@ if VERSION < v"1.1" || Sys.iswindows() && VERSION < v"1.3" isabspath(b) && return b A, a = _splitdrive(a) B, b = _splitdrive(b) - !isempty(B) && A != B && return string(B,b) + !isempty(B) && A != B && return string(B, b) C = isempty(B) ? A : B - isempty(a) ? string(C,b) : - occursin(_path_separator_re, a[end:end]) ? string(C,a,b) : - string(C,a,_pathsep(a,b),b) + isempty(a) ? string(C, b) : + occursin(_path_separator_re, a[end:end]) ? string(C, a, b) : + string(C, a, _pathsep(a, b), b) end joinpath(a::AbstractString, b::AbstractString) = joinpath(String(a), String(b)) joinpath(a, b, c, paths...) = joinpath(joinpath(a, b), c, paths...) @@ -423,7 +423,7 @@ end function is_in_target_dir_of_package(pkgpath, target) try # Safe failure - attempts to read disc. spaths = splitpath(pkgpath) - if (i = findfirst(==(target), spaths)) !== nothing && "src" in readdir(joinpath(spaths[1:i - 1]...)) + if (i = findfirst(==(target), spaths)) !== nothing && "src" in readdir(joinpath(spaths[1:i-1]...)) return true end return false @@ -442,9 +442,9 @@ end _Z = UInt32('Z') _z = UInt32('z') a::UInt32 = base <= 36 ? 10 : 36 - d = _0 <= _c <= _9 ? _c-_0 : - _A <= _c <= _Z ? _c-_A+ UInt32(10) : - _a <= _c <= _z ? _c-_a+a : UInt32(base) + d = _0 <= _c <= _9 ? _c - _0 : + _A <= _c <= _Z ? _c - _A + UInt32(10) : + _a <= _c <= _z ? _c - _a + a : UInt32(base) end @inline function uuid_kernel(s, i, u) @@ -521,9 +521,9 @@ function send_startup_time_message(timings) for (msg, thistime) in timings println( io, - lpad(string(round(thistime - starttime; sigdigits = 5)), 10), + lpad(string(round(thistime - starttime; sigdigits=5)), 10), " - ", msg, " (", - round(thistime - prevtime; sigdigits = 5), + round(thistime - prevtime; sigdigits=5), "s since last event)" ) prevtime = thistime diff --git a/test/requests/test_actions.jl b/test/requests/test_actions.jl index 9aa1f430..ad71ce41 100644 --- a/test/requests/test_actions.jl +++ b/test/requests/test_actions.jl @@ -4,7 +4,7 @@ settestdoc("using Base.Meta\n") @test any(c.command == "ReexportModule" for c in action_request_test(0, 15)) c = filter(c -> c.command == "ReexportModule", action_request_test(0, 15))[1] - + LanguageServer.workspace_executeCommand_request(LanguageServer.ExecuteCommandParams(missing, c.command, c.arguments), server, server.jr_endpoint) end @@ -19,7 +19,7 @@ end settestdoc("g(x) = x\nf(x) = x") @test any(c.command == "ExpandFunction" for c in action_request_test(0, 0)) @test any(c.command == "ExpandFunction" for c in action_request_test(1, 0)) - + LanguageServer.workspace_executeCommand_request(LanguageServer.ExecuteCommandParams(missing, c.command, c.arguments), server, server.jr_endpoint) closetestdoc() @@ -27,7 +27,7 @@ end @test any(c.command == "ExpandFunction" for c in action_request_test(0, 5)) c = filter(c -> c.command == "ExpandFunction", action_request_test(0, 5))[1] - + LanguageServer.workspace_executeCommand_request(LanguageServer.ExecuteCommandParams(missing, c.command, c.arguments), server, server.jr_endpoint) closetestdoc() end @@ -39,7 +39,7 @@ end e = LanguageServer.mark_errors(doc)[1] @test any(c.command == "FixMissingRef" for c in action_request_test(0, 5, diags=[e])) c = filter(c -> c.command == "FixMissingRef", action_request_test(0, 5, diags=[e]))[1] - + LanguageServer.workspace_executeCommand_request(LanguageServer.ExecuteCommandParams(missing, c.command, c.arguments), server, server.jr_endpoint) end @@ -48,10 +48,10 @@ end doc = settestdoc("using Base.Meta\nMeta.quot") @test LanguageServer.find_using_statement(doc.cst.args[2].args[1]) !== nothing - + @test any(c.command == "ExplicitPackageVarImport" for c in action_request_test(1, 1)) c = filter(c -> c.command == "ExplicitPackageVarImport", action_request_test(1, 1))[1] - + LanguageServer.workspace_executeCommand_request(LanguageServer.ExecuteCommandParams(missing, c.command, c.arguments), server, server.jr_endpoint) end @@ -59,10 +59,10 @@ end include("../test_shared_server.jl") doc = settestdoc("function f(arg::T) end\n") - + @test any(c.command == "DeleteUnusedFunctionArgumentName" for c in action_request_test(0, 12)) c = filter(c -> c.command == "DeleteUnusedFunctionArgumentName", action_request_test(0, 12))[1] - + LanguageServer.workspace_executeCommand_request(LanguageServer.ExecuteCommandParams(missing, c.command, c.arguments), server, server.jr_endpoint) end @@ -228,7 +228,7 @@ end @testitem "Update docstring signature" begin include("../test_shared_server.jl") - + doc = settestdoc(""" "hello" f(x) = x diff --git a/test/requests/test_completions.jl b/test/requests/test_completions.jl index a53fec32..6ebfe973 100644 --- a/test/requests/test_completions.jl +++ b/test/requests/test_completions.jl @@ -32,8 +32,7 @@ @test completion_test(6, 14).items[1].textEdit.range == LanguageServer.Range(6, 0, 6, 14) end -@testitem "path completions" begin -end +@testitem "path completions" begin end @testitem "import completions" begin include("../test_shared_server.jl") diff --git a/test/requests/test_misc.jl b/test/requests/test_misc.jl index af8754af..e467d96d 100644 --- a/test/requests/test_misc.jl +++ b/test/requests/test_misc.jl @@ -4,7 +4,7 @@ doc = settestdoc("ab") res = (LanguageServer.Position(0, 0), LanguageServer.Position(0, 2), LanguageServer.Position(0, 2)) - + @test LanguageServer.julia_getCurrentBlockRange_request(LanguageServer.VersionedTextDocumentPositionParams(LanguageServer.TextDocumentIdentifier(uri"untitled:testdoc"), 0, LanguageServer.Position(0, 0)), server, server.jr_endpoint) == res @test LanguageServer.julia_getCurrentBlockRange_request(LanguageServer.VersionedTextDocumentPositionParams(LanguageServer.TextDocumentIdentifier(uri"untitled:testdoc"), 0, LanguageServer.Position(0, 1)), server, server.jr_endpoint) == res diff --git a/test/test_bruteforce.jl b/test/test_bruteforce.jl index 37251c22..88af47f1 100644 --- a/test/test_bruteforce.jl +++ b/test/test_bruteforce.jl @@ -14,7 +14,7 @@ f(doc, offset) offset = nextind(get_text(doc), offset) end - end + end @info "Self-parse test" if get(ENV, "CI", false) != false @@ -24,7 +24,7 @@ empty!(server._documents) LanguageServer.load_folder(dirname(String(first(methods(LanguageServer.eval)).file)), server) on_all_docs(server, doc -> begin - @info "Testing LS functionality at all offsets" file=get_uri(doc) + @info "Testing LS functionality at all offsets" file = get_uri(doc) on_all_offsets(doc, function (doc, offset) tdi = LanguageServer.TextDocumentIdentifier(get_uri(doc)) pos = LanguageServer.Position(LanguageServer.get_position_from_offset(doc, offset)...) @@ -39,8 +39,8 @@ end) on_all_docs(server, doc -> begin - symbols=length(LanguageServer.textDocument_documentSymbol_request(LanguageServer.DocumentSymbolParams(LanguageServer.TextDocumentIdentifier(get_uri(doc)),missing, missing), server, server.jr_endpoint)) - @info "Found $symbols symbols" file=get_uri(doc) + symbols = length(LanguageServer.textDocument_documentSymbol_request(LanguageServer.DocumentSymbolParams(LanguageServer.TextDocumentIdentifier(get_uri(doc)), missing, missing), server, server.jr_endpoint)) + @info "Found $symbols symbols" file = get_uri(doc) end) LanguageServer.workspace_symbol_request(LanguageServer.WorkspaceSymbolParams("", missing, missing), server, server.jr_endpoint) diff --git a/test/test_document.jl b/test/test_document.jl index 42dc24fd..7a87ffa1 100644 --- a/test/test_document.jl +++ b/test/test_document.jl @@ -69,7 +69,7 @@ end s6 = "\n" d6 = Document(TextDocument(uri"untitled:none", s6, 0), false) - @test get_line_offsets(get_text_document(d6)) == [0,1] + @test get_line_offsets(get_text_document(d6)) == [0, 1] end @testitem "apply_text_edits" begin diff --git a/test/test_edit.jl b/test/test_edit.jl index b9b2a18a..fd378b4d 100644 --- a/test/test_edit.jl +++ b/test/test_edit.jl @@ -38,7 +38,7 @@ LanguageServer.textDocument_didClose_notification(LanguageServer.DidCloseTextDocumentParams(LanguageServer.TextDocumentIdentifier(uri"untitled:none")), server, nothing) - CSTParser.to_codeobject(old_cst) == CSTParser.to_codeobject(new_cst), old_cst, new_cst + CSTParser.to_codeobject(old_cst) == CSTParser.to_codeobject(new_cst), old_cst, new_cst end # techinically tests the same as test_document.jl, but should be changed to incremental re-parsing diff --git a/test/test_misc.jl b/test/test_misc.jl index c107fd06..1e2b30d2 100644 --- a/test/test_misc.jl +++ b/test/test_misc.jl @@ -1,6 +1,6 @@ @testitem "get_file_loc" begin import CSTParser - + str = "(x+y for x in X for y in Y if begin if true end end)" cst = CSTParser.parse(str) @test LanguageServer.get_file_loc(cst[2][5][1][1]) == (nothing, 20) diff --git a/test/test_shared_init_request.jl b/test/test_shared_init_request.jl index 358df0d9..deab7e48 100644 --- a/test/test_shared_init_request.jl +++ b/test/test_shared_init_request.jl @@ -1,50 +1,50 @@ import JSONRPC, LanguageServer init_request = LanguageServer.InitializeParams( - 9902, - missing, - nothing, - nothing, - missing, - LanguageServer.ClientCapabilities( - LanguageServer.WorkspaceClientCapabilities( - true, - LanguageServer.WorkspaceEditClientCapabilities(true, missing, missing), - LanguageServer.DidChangeConfigurationClientCapabilities(false), - LanguageServer.DidChangeWatchedFilesClientCapabilities(false,), - LanguageServer.WorkspaceSymbolClientCapabilities(true, missing), - LanguageServer.ExecuteCommandClientCapabilities(true), - missing, - missing - ), - LanguageServer.TextDocumentClientCapabilities( - LanguageServer.TextDocumentSyncClientCapabilities(true, true, true, true), - LanguageServer.CompletionClientCapabilities(true, LanguageServer.CompletionItemClientCapabilities(true, missing, missing, missing, missing, missing), missing, missing), - LanguageServer.HoverClientCapabilities(true, missing), - LanguageServer.SignatureHelpClientCapabilities(true, missing, missing), - LanguageServer.DeclarationClientCapabilities(false, missing), - missing, # DefinitionClientCapabilities(), - missing, # TypeDefinitionClientCapabilities(), - missing, # ImplementationClientCapabilities(), - missing, # ReferenceClientCapabilities(), - LanguageServer.DocumentHighlightClientCapabilities(true), - LanguageServer.DocumentSymbolClientCapabilities(true, missing, missing), - LanguageServer.CodeActionClientCapabilities(true, missing, missing), - LanguageServer.CodeLensClientCapabilities(true), - missing, # DocumentLinkClientCapabilities(), - missing, # DocumentColorClientCapabilities(), - LanguageServer.DocumentFormattingClientCapabilities(true), - missing, # DocumentRangeFormattingClientCapabilities(), - missing, # DocumentOnTypeFormattingClientCapabilities(), - LanguageServer.RenameClientCapabilities(true, true), - missing, # PublishDiagnosticsClientCapabilities(), - missing, # FoldingRangeClientCapabilities(), - missing, # SelectionRangeClientCapabilities() - ), + 9902, + missing, + nothing, + nothing, + missing, + LanguageServer.ClientCapabilities( + LanguageServer.WorkspaceClientCapabilities( + true, + LanguageServer.WorkspaceEditClientCapabilities(true, missing, missing), + LanguageServer.DidChangeConfigurationClientCapabilities(false), + LanguageServer.DidChangeWatchedFilesClientCapabilities(false,), + LanguageServer.WorkspaceSymbolClientCapabilities(true, missing), + LanguageServer.ExecuteCommandClientCapabilities(true), missing, missing ), - "off", + LanguageServer.TextDocumentClientCapabilities( + LanguageServer.TextDocumentSyncClientCapabilities(true, true, true, true), + LanguageServer.CompletionClientCapabilities(true, LanguageServer.CompletionItemClientCapabilities(true, missing, missing, missing, missing, missing), missing, missing), + LanguageServer.HoverClientCapabilities(true, missing), + LanguageServer.SignatureHelpClientCapabilities(true, missing, missing), + LanguageServer.DeclarationClientCapabilities(false, missing), + missing, # DefinitionClientCapabilities(), + missing, # TypeDefinitionClientCapabilities(), + missing, # ImplementationClientCapabilities(), + missing, # ReferenceClientCapabilities(), + LanguageServer.DocumentHighlightClientCapabilities(true), + LanguageServer.DocumentSymbolClientCapabilities(true, missing, missing), + LanguageServer.CodeActionClientCapabilities(true, missing, missing), + LanguageServer.CodeLensClientCapabilities(true), + missing, # DocumentLinkClientCapabilities(), + missing, # DocumentColorClientCapabilities(), + LanguageServer.DocumentFormattingClientCapabilities(true), + missing, # DocumentRangeFormattingClientCapabilities(), + missing, # DocumentOnTypeFormattingClientCapabilities(), + LanguageServer.RenameClientCapabilities(true, true), + missing, # PublishDiagnosticsClientCapabilities(), + missing, # FoldingRangeClientCapabilities(), + missing, # SelectionRangeClientCapabilities() + ), missing, missing - ) + ), + "off", + missing, + missing +)