Skip to content

Commit 713312a

Browse files
committed
create uri utilities
1 parent 4682c11 commit 713312a

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

src/completions.jl

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -145,19 +145,14 @@ completionurl(c::REPLCompletions.ModuleCompletion) = begin
145145
mod, name = c.parent, c.mod
146146
val = getfield′(mod, name)
147147
if val isa Module # module info
148-
parentmodule(val) == val || val (Main, Base, Core) ?
149-
"atom://julia-client/?moduleinfo=true&mod=$(name)" :
150-
"atom://julia-client/?moduleinfo=true&mod=$(mod).$(name)"
148+
urimoduleinfo(parentmodule(val) == val || val (Base, Core) ? name : "$mod.$name")
151149
else
152-
"atom://julia-client/?docs=true&mod=$(mod)&word=$(name)"
150+
uridocs(mod, name)
153151
end
154152
end
155-
completionurl(c::REPLCompletions.MethodCompletion) =
156-
"atom://julia-client/?docs=true&mod=$(c.method.module)&word=$(c.method.name)"
157-
completionurl(c::REPLCompletions.PackageCompletion) =
158-
"atom://julia-client/?moduleinfo=true&mod=$(c.package)"
159-
completionurl(c::REPLCompletions.KeywordCompletion) =
160-
"atom://julia-client/?docs=true&mod=Main&word=$(c.keyword)"
153+
completionurl(c::REPLCompletions.MethodCompletion) = uridocs(c.method.module, c.method.name)
154+
completionurl(c::REPLCompletions.PackageCompletion) = urimoduleinfo(c.package)
155+
completionurl(c::REPLCompletions.KeywordCompletion) = uridocs("Main", c.keyword)
161156

162157
completionmodule(mod, c) = shortstr(mod)
163158
completionmodule(mod, c::REPLCompletions.ModuleCompletion) = shortstr(c.parent)

src/refactor.jl

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ function renamerefactor(
2323
mod = getmodule(mod)
2424

2525
# catch field renaming
26-
modulenote = if (obj = first(split(full, '.'))) != old
26+
modnote = if (obj = first(split(full, '.'))) != old
2727
if (parentmod = getfield′(mod, obj)) isa Module && parentmod != mod
28-
"**NOTE**: `$old` is defined in `$parentmod` -- you may need the same rename refactorings in that module as well."
28+
modulenote(old, parentmod)
2929
else
3030
return Dict(:warning => "Rename refactoring on a field isn't available: `$obj.$old`")
3131
end
@@ -53,15 +53,14 @@ function renamerefactor(
5353
if val isa Undefined && Symbol(old) in keys(Docs.keywords)
5454
return Dict(:warning => "Keywords can't be renamed: `$old`")
5555
end
56-
# update modulenote
57-
if isempty(modulenote) && applicable(parentmodule, val) && (parentmod = parentmodule(val)) != mod
58-
modulenote =
59-
"**NOTE**: `$old` is defined in `$parentmod` -- you may need the same rename refactorings in that module as well."
56+
# update modnote
57+
if isempty(modnote) && applicable(parentmodule, val) && (parentmod = parentmodule(val)) != mod
58+
modnote = modulenote(old, parentmod)
6059
end
6160
kind, desc = globalrefactor(old, new, mod)
6261
return Dict(
6362
kind => kind === :success ?
64-
join(("_Global_ rename refactoring `$old` ⟹ `$new` succeeded.", modulenote, desc), "\n\n") :
63+
join(("_Global_ rename refactoring `$old` ⟹ `$new` succeeded.", modnote, desc), "\n\n") :
6564
desc
6665
)
6766
catch err
@@ -71,6 +70,9 @@ function renamerefactor(
7170
return Dict(:error => "Rename refactoring `$old` ⟹ `$new` failed")
7271
end
7372

73+
modulenote(old, parentmod) =
74+
"**NOTE**: `$old` is defined in `$parentmod` -- you may need the same rename refactorings in that module as well."
75+
7476
# local refactor
7577
# --------------
7678

@@ -127,9 +129,9 @@ function refactorfiles(old, new, mod, files)
127129
@info "Finish global rename refactoring" progress=1 _id=id
128130

129131
return if !isempty(refactoredfiles)
130-
filelist = ("- [$file](atom://julia-client/?open=true&file=$(file)&line=0)" for file in refactoredfiles)
132+
filelist = ("- [$file]($(uriopen(file)))" for file in refactoredfiles)
131133
(:success, string("Refactored files (all in `$mod` module):\n\n", join(filelist, '\n')))
132134
else
133-
(:warning, "No rename refactoring occured on `$old`")
135+
(:warning, "No rename refactoring occured on `$old` in `$mod` module.")
134136
end
135137
end

src/utils.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,13 @@ cangetdocs(mod::Module, word::Symbol) =
185185
cangetdocs(mod::Module, word::AbstractString) = cangetdocs(mod, Symbol(word))
186186
cangetdocs(mod::AbstractString, word::Union{Symbol, AbstractString}) = cangetdocs(getmodule(mod), word)
187187

188+
# uri utilties
189+
# ------------
190+
191+
uriopen(file, line = 0) = "atom://julia-client/?open=true&file=$(file)&line=$(line)"
192+
uridocs(mod, word) = "atom://julia-client/?docs=true&mod=$(mod)&word=$(word)"
193+
urimoduleinfo(mod) = "atom://julia-client/?moduleinfo=true&mod=$(mod)"
194+
188195
#=
189196
module file detections
190197

0 commit comments

Comments
 (0)