Skip to content

Commit

Permalink
Format files using DocumentFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
davidanthoff authored Mar 12, 2022
1 parent cc01b65 commit 2ce8e6b
Show file tree
Hide file tree
Showing 33 changed files with 338 additions and 345 deletions.
18 changes: 9 additions & 9 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ using LanguageServer
using Documenter

makedocs(;
modules=[LanguageServer],
authors="Julia VSCode",
repo="https://github.com/julia-vscode/LanguageServer.jl/blob/{commit}{path}#L{line}",
sitename="LanguageServer.jl",
format=Documenter.HTML(;
prettyurls=prettyurls = get(ENV, "CI", nothing) == "true",
modules = [LanguageServer],
authors = "Julia VSCode",
repo = "https://github.com/julia-vscode/LanguageServer.jl/blob/{commit}{path}#L{line}",
sitename = "LanguageServer.jl",
format = Documenter.HTML(;
prettyurls = prettyurls = get(ENV, "CI", nothing) == "true"
# canonical="https://www.julia-vscode.org/LanguageServer.jl",
# assets=String[],
),
pages=[
pages = [
"Home" => "index.md",
"Syntax Reference" => "syntax.md",
],
]
)

deploydocs(;
repo="github.com/julia-vscode/LanguageServer.jl",
repo = "github.com/julia-vscode/LanguageServer.jl"
)
32 changes: 16 additions & 16 deletions src/document.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mutable struct Document
_version::Int
server
root::Document
function Document(uri::AbstractString, text::AbstractString, workspace_file::Bool, server=nothing)
function Document(uri::AbstractString, text::AbstractString, workspace_file::Bool, server = nothing)
path = something(uri2filepath(uri), "")
path == "" || isabspath(path) || throw(LSRelativePath("Relative path `$path` is not valid."))
cst = CSTParser.parse(text, true)
Expand Down Expand Up @@ -77,7 +77,7 @@ function get_offset(doc::Document, line::Integer, character::Integer)
line_offsets = get_line_offsets(doc)
io = IOBuffer(get_text(doc))
try
seek(io, line_offsets[line + 1])
seek(io, line_offsets[line+1])
while character > 0
c = read(io, Char)
character -= 1
Expand All @@ -102,7 +102,7 @@ get_offset(doc, p::Position) = get_offset(doc, p.line, p.character)
get_offset(doc, r::Range) = get_offset(doc, r.start):get_offset(doc, r.stop)

# 1-based. Basically the index at which (line, character) can be found in the document.
function get_offset2(doc::Document, line::Integer, character::Integer, forgiving_mode=false)
function get_offset2(doc::Document, line::Integer, character::Integer, forgiving_mode = false)
line_offsets = get_line_offsets2!(doc)
text = get_text(doc)

Expand All @@ -113,9 +113,9 @@ function get_offset2(doc::Document, line::Integer, character::Integer, forgiving
throw(LSOffsetError("get_offset2 crashed. More diagnostics:\nline=$line\nline_offsets='$line_offsets'"))
end

line_offset = line_offsets[line + 1]
line_offset = line_offsets[line+1]

next_line_offset = line + 1 < length(line_offsets) ? line_offsets[line + 2] : nextind(text, lastindex(text))
next_line_offset = line + 1 < length(line_offsets) ? line_offsets[line+2] : nextind(text, lastindex(text))

pos = line_offset

Expand All @@ -134,7 +134,7 @@ function get_offset2(doc::Document, line::Integer, character::Integer, forgiving
pos = nextind(text, pos)
end

return pos
return pos
end

# Note: to be removed
Expand Down Expand Up @@ -168,33 +168,33 @@ Updates the doc._line_offsets field, an n length Array each entry of which
gives the byte offset position of the start of each line. This always starts
with 0 for the first line (even if empty).
"""
function get_line_offsets(doc::Document, force=false)
function get_line_offsets(doc::Document, force = false)
if force || doc._line_offsets === nothing
doc._line_offsets = Int[0]
text = get_text(doc)
ind = firstindex(text)
while ind <= lastindex(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!(doc._line_offsets, ind)
ind = nextind(text, ind)
end
end
end
return doc._line_offsets
end

function get_line_offsets2!(doc::Document, force=false)
function get_line_offsets2!(doc::Document, force = false)
if force || doc._line_offsets2 === nothing
doc._line_offsets2 = Int[1]
text = get_text(doc)
ind = firstindex(text)
while ind <= lastindex(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!(doc._line_offsets2, ind + 1)
Expand All @@ -214,12 +214,12 @@ function get_line_of(line_offsets::Vector{Int}, 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

Expand All @@ -240,7 +240,7 @@ function get_position_at(doc::Document, offset::Integer)
c = read(io, Char)
character += 1
if UInt32(c) >= 0x010000
character += 1
character += 1
end
end
close(io)
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/messagedefs.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
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)
2 changes: 1 addition & 1 deletion src/languageserverinstance.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ mutable struct LanguageServerInstance

shutdown_requested::Bool

function LanguageServerInstance(pipe_in, pipe_out, env_path="", depot_path="", err_handler=nothing, symserver_store_path=nothing, download=true, symbolcache_upstream = nothing)
function LanguageServerInstance(pipe_in, pipe_out, env_path = "", depot_path = "", err_handler = nothing, symserver_store_path = nothing, download = true, symbolcache_upstream = nothing)
new(
JSONRPC.JSONRPCEndpoint(pipe_in, pipe_out, err_handler),
Set{String}(),
Expand Down
4 changes: 2 additions & 2 deletions src/multienv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -94,7 +94,7 @@ 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

Expand Down
16 changes: 8 additions & 8 deletions src/protocol/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ end
# Diagnostics
const DiagnosticSeverity = Int
const DiagnosticSeverities = (Error = 1,
Warning = 2,
Information = 3,
Hint = 4)
Warning = 2,
Information = 3,
Hint = 4)

const DiagnosticTag = Int
const DiagnosticTags = (Unnecessary = 1,
Deprecated = 2)
Deprecated = 2)

@dict_readable struct DiagnosticRelatedInformation
location::Location
Expand Down Expand Up @@ -105,7 +105,7 @@ end
# Markup
const MarkupKind = String
const MarkupKinds = (PlainText = "plaintext",
Markdown = "markdown")
Markdown = "markdown")

mutable struct MarkupContent
kind::MarkupKind
Expand All @@ -127,9 +127,9 @@ Base.hash(x::MarkedString) = hash(x.value) # for unique
# Window
const MessageType = Int
const MessageTypes = (Error = 1,
Warning = 2,
Info = 3,
Log = 4)
Warning = 2,
Info = 3,
Log = 4)

struct ShowMessageParams <: Outbound
type::MessageType
Expand Down
54 changes: 27 additions & 27 deletions src/protocol/completion.jl
Original file line number Diff line number Diff line change
@@ -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)
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)
TriggerCharacter = 2,
TriggerForIncompleteCompletion = 3)

const InsertTextFormat = Int
const InsertTextFormats = (PlainText = 1,
Snippet = 2)
Snippet = 2)

@dict_readable struct CompletionTagClientCapabilities
valueSet::Vector{CompletionItemTag}
Expand Down
8 changes: 4 additions & 4 deletions src/protocol/configuration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ end
# File watching
const FileChangeType = Int
const FileChangeTypes = (Created = 1,
Changed = 2,
Deleted = 3)
Changed = 2,
Deleted = 3)

const WatchKind = Int
const WatchKinds = (Create = 1,
Change = 2,
Delete = 4)
Change = 2,
Delete = 4)


@dict_readable struct FileEvent
Expand Down
12 changes: 6 additions & 6 deletions src/protocol/document.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct CreateFile <: Outbound
kind::String
uri::DocumentUri
options::Union{CreateFileOptions,Missing}
CreateFile(uri, options=missing) = new("create", uri, options)
CreateFile(uri, options = missing) = new("create", uri, options)
end

struct RenameFileOptions <: Outbound
Expand All @@ -24,7 +24,7 @@ struct RenameFile <: Outbound
oldUri::DocumentUri
newUri::DocumentUri
options::Union{RenameFileOptions,Missing}
RenameFile(uri, options=missing) = new("rename", uri, options)
RenameFile(uri, options = missing) = new("rename", uri, options)
end

struct DeleteFileOptions <: Outbound
Expand All @@ -36,7 +36,7 @@ struct DeleteFile <: Outbound
kind::String
uri::DocumentUri
options::Union{DeleteFileOptions,Missing}
DeleteFile(uri, options=missing) = new("delete", uri, options)
DeleteFile(uri, options = missing) = new("delete", uri, options)
end


Expand Down Expand Up @@ -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
Expand All @@ -98,8 +98,8 @@ end

const TextDocumentSaveReason = Int
const TextDocumentSaveReasons = (Manual = 1,
AfterDelay = 2,
FocusOut = 3)
AfterDelay = 2,
FocusOut = 3)

@dict_readable struct WillSaveTextDocumentParams
textDocument::TextDocumentIdentifier
Expand Down
18 changes: 9 additions & 9 deletions src/protocol/features.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ 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.organiseImports")
QuickFix = "quickfix",
Refactor = "refactor",
RefactorExtract = "refactor.extract",
RefactorInline = "refactor.inline",
RefactorRewrite = "refactor.rewrite",
Source = "source",
SourceOrganizeImports = "source.organiseImports")

@dict_readable struct CodeActionKindCapabilities
valueSet::Vector{CodeActionKind}
Expand Down Expand Up @@ -210,8 +210,8 @@ end
# Folding
const FoldingRangeKind = String
const FoldingRangeKinds = (Comment = "comment",
Imports = "imports",
Region = "region")
Imports = "imports",
Region = "region")

@dict_readable struct FoldingRangeClientCapabilities <: Outbound
dynamicRegistration::Union{Bool,Missing}
Expand Down
2 changes: 1 addition & 1 deletion src/protocol/goto.jl
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,4 @@ end
workDoneToken::Union{Int,String,Missing} # ProgressToken
partialResultToken::Union{Int,String,Missing} # ProgressToken
context::ReferenceContext
end
end
Loading

0 comments on commit 2ce8e6b

Please sign in to comment.