1
+ # path utilities
2
+ # --------------
3
+
1
4
include (" path_matching.jl" )
2
5
3
6
isuntitled (p) = occursin (r" ^(\.\\ |\. /)?untitled-[\d\w ]+(:\d +)?$" , p)
@@ -99,6 +102,9 @@ function md_hlines(md)
99
102
return MD (v)
100
103
end
101
104
105
+ # string utilties
106
+ # ---------------
107
+
102
108
function strlimit (str:: AbstractString , limit:: Int = 30 , ellipsis:: AbstractString = " …" )
103
109
will_append = length (str) > limit
104
110
@@ -122,33 +128,39 @@ shortstr(val) = strlimit(string(val), 20)
122
128
struct Undefined end
123
129
124
130
# get utilities
131
+ # -------------
132
+
125
133
using CodeTools
126
134
127
135
"""
128
- getfield′(mod::Module, name::String , default = Undefined())
136
+ getfield′(mod::Module, name::AbstractString , default = Undefined())
129
137
getfield′(mod::Module, name::Symbol, default = Undefined())
138
+ getfield′(mod::AbstractString, name::Symbol, default = Undefined())
130
139
getfield′(object, name::Symbol, default = Undefined())
140
+ getfield′(object, name::AbstractString, default = Undefined())
131
141
132
142
Returns the specified field of a given `Module` or some arbitrary `object`,
133
143
or `default` if no such a field is found.
134
144
"""
135
- getfield′ (mod:: Module , name:: String , default = Undefined ()) = CodeTools. getthing (mod, name, default)
145
+ getfield′ (mod:: Module , name:: AbstractString , default = Undefined ()) = CodeTools. getthing (mod, name, default)
136
146
getfield′ (mod:: Module , name:: Symbol , default = Undefined ()) = getfield′ (mod, string (name), default)
147
+ getfield′ (mod:: AbstractString , name:: Symbol , default = Undefined ()) = getfield′ (getmodule (mod), string (name), default)
137
148
getfield′ (@nospecialize (object), name:: Symbol , default = Undefined ()) = isdefined (object, name) ? getfield (object, name) : default
149
+ getfield′ (@nospecialize (object), name:: AbstractString , default = Undefined ()) = isdefined (object, name) ? getfield (object, Symbol (name)) : default
138
150
139
151
"""
140
- getmodule(mod::String )
141
- getmodule(parent::Union{Nothing, Module}, mod::String )
152
+ getmodule(mod::AbstractString )
153
+ getmodule(parent::Union{Nothing, Module}, mod::AbstractString )
142
154
getmodule(code::AbstractString, pos; filemod)
143
155
144
156
Calls `CodeTools.getmodule(args...)`, but returns `Main` instead of `nothing` in a fallback case.
145
157
"""
146
158
getmodule (args... ) = (m = CodeTools. getmodule (args... )) === nothing ? Main : m
147
159
148
- getmethods (mod:: Module , word:: String ) = methods (CodeTools. getthing (mod, word))
149
- getmethods (mod:: String , word:: String ) = getmethods (getmodule (mod), word)
160
+ getmethods (mod:: Module , word:: AbstractString ) = methods (CodeTools. getthing (mod, word))
161
+ getmethods (mod:: AbstractString , word:: AbstractString ) = getmethods (getmodule (mod), word)
150
162
151
- getdocs (mod:: Module , word:: String , fallbackmod:: Module = Main) = begin
163
+ getdocs (mod:: Module , word:: AbstractString , fallbackmod:: Module = Main) = begin
152
164
md = if Symbol (word) in keys (Docs. keywords)
153
165
Core. eval (Main, :(@doc ($ (Symbol (word)))))
154
166
else
@@ -164,13 +176,14 @@ getdocs(mod::Module, word::String, fallbackmod::Module = Main) = begin
164
176
end
165
177
md_hlines (md)
166
178
end
167
- getdocs (mod:: String , word:: String , fallbackmod:: Module = Main) =
179
+ getdocs (mod:: AbstractString , word:: AbstractString , fallbackmod:: Module = Main) =
168
180
getdocs (getmodule (mod), word, fallbackmod)
169
181
170
182
cangetdocs (mod:: Module , word:: Symbol ) =
171
183
Base. isbindingresolved (mod, word) &&
172
184
! Base. isdeprecated (mod, word)
173
- cangetdocs (mod:: Module , word:: String ) = cangetdocs (mod, Symbol (word))
185
+ cangetdocs (mod:: Module , word:: AbstractString ) = cangetdocs (mod, Symbol (word))
186
+ cangetdocs (mod:: AbstractString , word:: Union{Symbol, AbstractString} ) = cangetdocs (getmodule (mod), word)
174
187
175
188
#=
176
189
module file detections
0 commit comments