File tree Expand file tree Collapse file tree 3 files changed +14
-6
lines changed Expand file tree Collapse file tree 3 files changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -127,7 +127,7 @@ If this is successful it traverses the code associated with the loaded file.
127127"""
128128function followinclude (x, state:: State )
129129 if typof (x) === Call && typof (x. args[1 ]) === IDENTIFIER && valof (x. args[1 ]) == " include"
130- path = get_path (x)
130+ path = get_path (x, state )
131131 if isempty (path)
132132 elseif hasfile (state. server, path)
133133 elseif canloadfile (state. server, path)
@@ -154,8 +154,7 @@ function followinclude(x, state::State)
154154 state. file = oldfile
155155 pop! (state. included_files)
156156 else
157- # (printstyled(">>>>Can't follow include", color = :red);printstyled(" $(Expr(x)) from $(dirname(state.path))\n"))
158- # error handling for broken `include` here
157+ seterror! (x, MissingFile)
159158 end
160159 end
161160end
Original file line number Diff line number Diff line change @@ -9,7 +9,9 @@ PointlessOR,
99PointlessAND,
1010UnusedBinding,
1111InvalidTypeDeclaration,
12- IncludeLoop)
12+ IncludeLoop,
13+ MissingFile)
14+
1315
1416const LintCodeDescriptions = Dict {LintCodes,String} (
1517 IncorrectCallNargs => " An incorrect number of function arguments has been passed." ,
@@ -21,7 +23,8 @@ const LintCodeDescriptions = Dict{LintCodes,String}(
2123 PointlessAND => " The first argument of a `&&` call is `false`." ,
2224 UnusedBinding => " The variable name has been bound but not used." ,
2325 InvalidTypeDeclaration => " A non-DataType has been used in a type declaration statement." ,
24- IncludeLoop => " Loop detected, this file has already been included."
26+ IncludeLoop => " Loop detected, this file has already been included." ,
27+ MissingFile => " The included file can not be found."
2528)
2629
2730haserror (m:: Meta ) = m. error != = nothing
Original file line number Diff line number Diff line change 9494Usually called on the argument to `include` calls, and attempts to determine
9595the path of the file to be included. Has limited support for `joinpath` calls.
9696"""
97- function get_path (x:: EXPR )
97+ function get_path (x:: EXPR , state )
9898 if typof (x) === Call && length (x. args) == 4
9999 parg = x. args[3 ]
100100 if CSTParser. is_lit_string (parg)
@@ -105,6 +105,8 @@ function get_path(x::EXPR)
105105 for i = 2 : length (parg. args)
106106 arg = parg. args[i]
107107 if typof (arg) === PUNCTUATION
108+ elseif _is_macrocall_to_BaseDIR (arg) # Assumes @__DIR__ points to Base macro.
109+ path = string (path, " /" , dirname (getpath (state. file)))
108110 elseif CSTParser. is_lit_string (arg)
109111 path = string (path, " /" , CSTParser. str_value (arg))
110112 else
@@ -116,3 +118,7 @@ function get_path(x::EXPR)
116118 end
117119 return " "
118120end
121+
122+ _is_macrocall_to_BaseDIR (arg) = typof (arg) === CSTParser. MacroCall && length (arg. args) == 1 &&
123+ typof (arg. args[1 ]) === CSTParser. MacroName && length (arg. args[1 ]. args) == 2 &&
124+ valof (arg. args[1 ]. args[2 ]) == " __DIR__"
You can’t perform that action at this time.
0 commit comments