1+ # file utilities
2+ # --------------
3+
4+ function isfile′ (p)
5+ try
6+ isfile (p)
7+ catch
8+ false
9+ end
10+ end
11+
12+ iswritablefile (file) = Base. uperm (file) == 0x06
13+ nonwritablefiles (files) = filter (! iswritablefile, files)
14+
15+ # path utilities
16+ # --------------
17+
118include (" path_matching.jl" )
219
320isuntitled (p) = occursin (r" ^(\.\\ |\. /)?untitled-[\d\w ]+(:\d +)?$" , p)
@@ -12,14 +29,6 @@ function realpath′(p)
1229 end
1330end
1431
15- function isfile′ (p)
16- try
17- isfile (p)
18- catch
19- false
20- end
21- end
22-
2332using Pkg, OrderedCollections
2433function finddevpackages ()
2534 usage_file = joinpath (Pkg. logdir (), " manifest_usage.toml" )
@@ -99,6 +108,9 @@ function md_hlines(md)
99108 return MD (v)
100109end
101110
111+ # string utilties
112+ # ---------------
113+
102114function strlimit (str:: AbstractString , limit:: Int = 30 , ellipsis:: AbstractString = " …" )
103115 will_append = length (str) > limit
104116
@@ -122,34 +134,56 @@ shortstr(val) = strlimit(string(val), 20)
122134struct Undefined end
123135
124136# get utilities
137+ # -------------
138+
125139using CodeTools
126140
127141"""
128- getfield′(mod::Module, name::String , default = Undefined())
142+ getfield′(mod::Module, name::AbstractString , default = Undefined())
129143 getfield′(mod::Module, name::Symbol, default = Undefined())
144+ getfield′(mod::AbstractString, name::Symbol, default = Undefined())
130145 getfield′(object, name::Symbol, default = Undefined())
146+ getfield′(object, name::AbstractString, default = Undefined())
131147
132148Returns the specified field of a given `Module` or some arbitrary `object`,
133149or `default` if no such a field is found.
134150"""
135- getfield′ (mod:: Module , name:: String , default = Undefined ()) = CodeTools. getthing (mod, name, default)
151+ getfield′ (mod:: Module , name:: AbstractString , default = Undefined ()) = CodeTools. getthing (mod, name, default)
136152getfield′ (mod:: Module , name:: Symbol , default = Undefined ()) = getfield′ (mod, string (name), default)
153+ getfield′ (mod:: AbstractString , name:: Symbol , default = Undefined ()) = getfield′ (getmodule (mod), string (name), default)
137154getfield′ (@nospecialize (object), name:: Symbol , default = Undefined ()) = isdefined (object, name) ? getfield (object, name) : default
155+ getfield′ (@nospecialize (object), name:: AbstractString , default = Undefined ()) = isdefined (object, name) ? getfield (object, Symbol (name)) : default
138156
139157"""
140- getmodule(mod::String )
141- getmodule(parent::Union{Nothing, Module}, mod::String )
158+ getmodule(mod::AbstractString )
159+ getmodule(parent::Union{Nothing, Module}, mod::AbstractString )
142160 getmodule(code::AbstractString, pos; filemod)
143161
144162Calls `CodeTools.getmodule(args...)`, but returns `Main` instead of `nothing` in a fallback case.
145163"""
146164getmodule (args... ) = (m = CodeTools. getmodule (args... )) === nothing ? Main : m
147165
148- getmethods (mod:: Module , word:: String ) = methods (CodeTools. getthing (mod, word))
149- getmethods (mod:: String , word:: String ) = getmethods (getmodule (mod), word)
166+ """
167+ getmethods(mod::Module, word::AbstractString)
168+ getmethods(mod::AbstractString, word::AbstractString)
169+
170+ Returns the [`MethodList`](@ref) for `word`, which is bound within `mod` module.
171+ """
172+ getmethods (mod:: Module , word:: AbstractString ) = methods (CodeTools. getthing (mod, word))
173+ getmethods (mod:: AbstractString , word:: AbstractString ) = getmethods (getmodule (mod), word)
174+
175+ """
176+ getdocs(mod::Module, word::AbstractString, fallbackmod::Module = Main)
177+ getdocs(mod::AbstractString, word::AbstractString, fallbackmod::Module = Main)
178+
179+ Retrieves docs for `mod.word` with [`@doc`](@ref) macro. If `@doc` is not available
180+ within `mod` module, `@doc` will be evaluated in `fallbackmod` module if possible.
150181
151- getdocs (mod:: Module , word:: String , fallbackmod:: Module = Main) = begin
152- md = if Symbol (word) in keys (Docs. keywords)
182+ !!! note
183+ You may want to run [`cangetdocs`](@ref) in advance.
184+ """
185+ getdocs (mod:: Module , word:: AbstractString , fallbackmod:: Module = Main) = begin
186+ md = if iskeyword (word)
153187 Core. eval (Main, :(@doc ($ (Symbol (word)))))
154188 else
155189 docsym = Symbol (" @doc" )
@@ -164,13 +198,39 @@ getdocs(mod::Module, word::String, fallbackmod::Module = Main) = begin
164198 end
165199 md_hlines (md)
166200end
167- getdocs (mod:: String , word:: String , fallbackmod:: Module = Main) =
201+ getdocs (mod:: AbstractString , word:: AbstractString , fallbackmod:: Module = Main) =
168202 getdocs (getmodule (mod), word, fallbackmod)
169203
204+ """
205+ cangetdocs(mod::Module, word::Symbol)
206+ cangetdocs(mod::Module, word::AbstractString)
207+ cangetdocs(mod::AbstractString, word::Union{Symbol, AbstractString})
208+
209+ Checks if the documentation bindings for `mod.word` is resolved and `mod.word`
210+ is not deprecated.
211+ """
170212cangetdocs (mod:: Module , word:: Symbol ) =
171213 Base. isbindingresolved (mod, word) &&
172214 ! Base. isdeprecated (mod, word)
173- cangetdocs (mod:: Module , word:: String ) = cangetdocs (mod, Symbol (word))
215+ cangetdocs (mod:: Module , word:: AbstractString ) = cangetdocs (mod, Symbol (word))
216+ cangetdocs (mod:: AbstractString , word:: Union{Symbol, AbstractString} ) = cangetdocs (getmodule (mod), word)
217+
218+ # is utilities
219+ # ------------
220+
221+ iskeyword (word:: Symbol ) = word in keys (Docs. keywords)
222+ iskeyword (word:: AbstractString ) = iskeyword (Symbol (word))
223+
224+ ismacro (ct:: AbstractString ) = startswith (ct, ' @' ) || endswith (ct, ' "' )
225+ ismacro (f:: Function ) = startswith (string (methods (f). mt. name), " @" )
226+
227+ # uri utilties
228+ # ------------
229+
230+ uriopen (file, line = 0 ) = " atom://julia-client/?open=true&file=$(file) &line=$(line) "
231+ uridocs (mod, word) = " atom://julia-client/?docs=true&mod=$(mod) &word=$(word) "
232+ urigoto (mod, word) = " atom://julia-client/?goto=true&mod=$(mod) &word=$(word) "
233+ urimoduleinfo (mod) = " atom://julia-client/?moduleinfo=true&mod=$(mod) "
174234
175235#=
176236module file detections
0 commit comments