mirror of
				https://github.com/janet-lang/janet
				synced 2025-10-31 07:33:01 +00:00 
			
		
		
		
	Make flycheck follow GNU standards for errors.
This commit is contained in:
		| @@ -2442,22 +2442,25 @@ | ||||
|   (put env :source (or src (if-not path-is-file spath path))) | ||||
|   (var exit-error nil) | ||||
|   (var exit-fiber nil) | ||||
|   (defn chunks [buf _] (file/read f 2048 buf)) | ||||
|   (defn chunks [buf _] (file/read f 4096 buf)) | ||||
|   (defn bp [&opt x y] | ||||
|     (when exit | ||||
|       (bad-parse x y) | ||||
|       (os/exit 1)) | ||||
|     (put env :exit true) | ||||
|     (def [line col] (:where x)) | ||||
|     (def pe (string (:error x) " in " y " around line " line ", column " col)) | ||||
|     (set exit-error pe)) | ||||
|     (def buf @"") | ||||
|     (with-dyns [:err buf :err-color false] | ||||
|       (bad-parse x y)) | ||||
|     (set exit-error (string/slice buf 0 -2))) | ||||
|   (defn bc [&opt x y z a b] | ||||
|     (when exit | ||||
|       (bad-compile x y z a b) | ||||
|       (os/exit 1)) | ||||
|     (put env :exit true) | ||||
|     (def ce (string x " while compiling " z)) | ||||
|     (set exit-error ce) | ||||
|     (def buf @"") | ||||
|     (with-dyns [:err buf :err-color false] | ||||
|       (bad-compile x nil z a b)) | ||||
|     (set exit-error (string/slice buf 0 -2)) | ||||
|     (set exit-fiber y)) | ||||
|   (unless f | ||||
|     (error (string "could not find file " path))) | ||||
| @@ -2469,7 +2472,8 @@ | ||||
|                   :on-status (fn [f x] | ||||
|                                (when (not= (fiber/status f) :dead) | ||||
|                                  (when exit | ||||
|                                    (debug/stacktrace f x) | ||||
|                                    (eprint x) | ||||
|                                    (debug/stacktrace f) | ||||
|                                    (eflush) | ||||
|                                    (os/exit 1)) | ||||
|                                  (put env :exit true) | ||||
| @@ -3252,7 +3256,10 @@ | ||||
| (defn- use-2 [evaluator args] | ||||
|   (each a args (import* (string a) :prefix "" :evaluator evaluator))) | ||||
|  | ||||
| (defn- evaluator | ||||
| (defn flycheck-evaluator | ||||
|   ``An evaluator function that is passed to `run-context` that lints (flychecks) code. | ||||
|   This means code will parsed and compiled, macros executed, but the code will not be run. | ||||
|   Used by `flycheck`.`` | ||||
|   [thunk source env where] | ||||
|   (when (tuple? source) | ||||
|     (def head (source 0)) | ||||
| @@ -3266,20 +3273,25 @@ | ||||
|       (thunk) | ||||
|       # Use | ||||
|       (= 'use head) | ||||
|       (use-2 evaluator (tuple/slice source 1)) | ||||
|       (use-2 flycheck-evaluator (tuple/slice source 1)) | ||||
|       # Import-like form | ||||
|       (importers head) | ||||
|       (let [[l c] (tuple/sourcemap source) | ||||
|             newtup (tuple/setmap (tuple ;source :evaluator evaluator) l c)] | ||||
|             newtup (tuple/setmap (tuple ;source :evaluator flycheck-evaluator) l c)] | ||||
|         ((compile newtup env where)))))) | ||||
|  | ||||
| (defn flycheck | ||||
|   ``Check a file for errors without running the file. Found errors will be printed to stderr | ||||
|   in the usual format. Macros will still be executed, however, so | ||||
|   arbitrary execution is possible. Other arguments are the same as dofile. `path` can also be | ||||
|   a file value such as stdin.`` | ||||
|   a file value such as stdin. Returns nil.`` | ||||
|   [path &keys kwargs] | ||||
|   (dofile path :evaluator evaluator ;(kvs kwargs))) | ||||
|   (try | ||||
|     (dofile path :evaluator flycheck-evaluator ;(kvs kwargs)) | ||||
|     ([e f] | ||||
|      (eprint e) | ||||
|      (debug/stacktrace f))) | ||||
|   nil) | ||||
|  | ||||
| ### | ||||
| ### | ||||
|   | ||||
| @@ -102,7 +102,9 @@ void janet_stacktrace(JanetFiber *fiber, Janet err) { | ||||
|     int32_t fi; | ||||
|     const char *errstr = (const char *)janet_to_string(err); | ||||
|     JanetFiber **fibers = NULL; | ||||
|     int wrote_error = 0; | ||||
|  | ||||
|     /* Don't print error line if it is nil. */ | ||||
|     int wrote_error = janet_checktype(err, JANET_NIL); | ||||
|  | ||||
|     int print_color = janet_truthy(janet_dyn("err-color")); | ||||
|     if (print_color) janet_eprintf("\x1b[31m"); | ||||
| @@ -302,7 +304,6 @@ static Janet cfun_debug_stacktrace(int32_t argc, Janet *argv) { | ||||
|     janet_arity(argc, 1, 2); | ||||
|     JanetFiber *fiber = janet_getfiber(argv, 0); | ||||
|     Janet x = argc == 1 ? janet_wrap_nil() : argv[1]; | ||||
|     x = janet_checktype(x, JANET_NIL) ? fiber->last_value : x; | ||||
|     janet_stacktrace(fiber, x); | ||||
|     return argv[0]; | ||||
| } | ||||
| @@ -382,7 +383,7 @@ static const JanetReg debug_cfuns[] = { | ||||
|         JDOC("(debug/stacktrace fiber &opt err)\n\n" | ||||
|              "Prints a nice looking stacktrace for a fiber. Can optionally provide " | ||||
|              "an error value to print the stack trace with. If `err` is nil or not " | ||||
|              "provided, will default to `(fiber/last-value fiber)`. Returns the fiber.") | ||||
|              "provided, will skipp the error line. Returns the fiber.") | ||||
|     }, | ||||
|     { | ||||
|         "debug/lineage", cfun_debug_lineage, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Calvin Rose
					Calvin Rose