From 4a121f70b0723a55df289bb4f08948167fcb8090 Mon Sep 17 00:00:00 2001 From: Phil Hagelberg Date: Sat, 25 Nov 2023 21:43:08 -0800 Subject: [PATCH] Add selfcheck make target. Also cleans up repeated path options in the makefile, and cleans up warnings where fennel-ls warns on itself. There were some unused functions; I just put a _ before their name but that might be a bit silly. Maybe they should be removed? Or just left alone? --- Makefile | 14 ++++++++------ src/fennel-ls.fnl | 1 - src/fennel-ls/compiler.fnl | 8 ++++---- src/fennel-ls/handlers.fnl | 4 +--- src/fennel-ls/language.fnl | 10 +++++----- src/fennel-ls/state.fnl | 2 +- src/fennel-ls/utils.fnl | 2 +- 7 files changed, 20 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index 50fb3df..7fcc6fa 100644 --- a/Makefile +++ b/Makefile @@ -10,23 +10,22 @@ DESTDIR ?= PREFIX ?= /usr/local BINDIR ?= $(PREFIX)/bin -.PHONY: clean test install ci +OPTS=--add-package-path "./src/?.lua" --add-fennel-path "./src/?.fnl" + +.PHONY: clean test install ci selfcheck all: $(EXE) $(EXE): $(SRC) echo "#!/usr/bin/env $(LUA)" > $@ - LUA_PATH="./src/?.lua" \ - FENNEL_PATH="./src/?.fnl" \ - $(FENNEL) --require-as-include --compile src/fennel-ls.fnl >> $@ + $(FENNEL) $(OPTS) --require-as-include --compile src/fennel-ls.fnl >> $@ chmod 755 $@ clean: rm -f $(EXE) test: - TESTING=1 LUA_PATH="./src/?.lua;./?.lua" FENNEL_PATH="./src/?.fnl;./?.fnl" \ - $(FENNEL) test/init.fnl + TESTING=1 $(FENNEL) $(OPTS) test/init.fnl testall: $(MAKE) test LUA=lua5.1 @@ -39,3 +38,6 @@ install: $(EXE) mkdir -p $(DESTDIR)$(BINDIR) && cp $< $(DESTDIR)$(BINDIR)/ ci: testall $(EXE) + +selfcheck: + $(FENNEL) $(OPTS) src/fennel-ls.fnl --check $(SRC) diff --git a/src/fennel-ls.fnl b/src/fennel-ls.fnl index 5e4f83f..9d672de 100644 --- a/src/fennel-ls.fnl +++ b/src/fennel-ls.fnl @@ -2,7 +2,6 @@ (local json-rpc (require :fennel-ls.json-rpc)) (local state (require :fennel-ls.state)) (local diagnostics (require :fennel-ls.diagnostics)) -(local {: view} (require :fennel)) (λ check [filename] (let [server (doto {} diff --git a/src/fennel-ls/compiler.fnl b/src/fennel-ls/compiler.fnl index ecaec76..813d679 100644 --- a/src/fennel-ls/compiler.fnl +++ b/src/fennel-ls/compiler.fnl @@ -3,7 +3,7 @@ This file is responsible for the low level tasks of analysis. Its main job is to recieve a file object and run all of the basic analysis that will be used later by fennel-ls.language to answer requests from the client." -(local {: sym? : list? : sequence? : table? : sym : view &as fennel} (require :fennel)) +(local {: sym? : list? : sequence? : table? : sym &as fennel} (require :fennel)) (local message (require :fennel-ls.message)) (local utils (require :fennel-ls.utils)) (local searcher (require :fennel-ls.searcher)) @@ -122,7 +122,7 @@ later by fennel-ls.language to answer requests from the client." (table.remove keys)))))) (recurse binding [])) - (λ mutate [?definition binding scope] + (λ mutate [_?definition binding scope] ;; for now, mutating a field counts as a reference I guess (λ recurse [binding keys] (if (sym? binding) @@ -196,7 +196,7 @@ later by fennel-ls.language to answer requests from the client." (define (sym :nil) binding scope)) (λ compile-each [ast bindings scope] - (each [i binding (ipairs bindings)] + (each [_ binding (ipairs bindings)] (define (sym :nil) binding scope))) (λ compile-fn [ast scope] @@ -270,7 +270,7 @@ later by fennel-ls.language to answer requests from the client." (table.insert allowed-globals :love) ;; TODO clean up this code. It's awful now that there is error handling - (let [macro-file? (= (: file.text :sub 1 24) ";; fennel-ls: macro-file") + (let [macro-file? (= (file.text:sub 1 24) ";; fennel-ls: macro-file") plugin {:name "fennel-ls" :versions ["1.3.2"] diff --git a/src/fennel-ls/handlers.fnl b/src/fennel-ls/handlers.fnl index 065f68a..9e1d3b8 100644 --- a/src/fennel-ls/handlers.fnl +++ b/src/fennel-ls/handlers.fnl @@ -12,8 +12,6 @@ Every time the client sends a message, it gets handled by a function in the corr (local formatter (require :fennel-ls.formatter)) (local utils (require :fennel-ls.utils)) -(local {: view} (require :fennel)) - (local requests []) (local notifications []) @@ -168,7 +166,7 @@ Every time the client sends a message, it gets handled by a function in the corr _ {: label :kind kinds.Field})))) _ nil)))) -(λ create-completion-item [self file name scope] +(λ _create-completion-item [self file name scope] (let [result (language.search-name-and-scope self file name scope)] {:label result.label :kind result.kind})) diff --git a/src/fennel-ls/language.fnl b/src/fennel-ls/language.fnl index ce03858..a4ae994 100644 --- a/src/fennel-ls/language.fnl +++ b/src/fennel-ls/language.fnl @@ -2,7 +2,7 @@ The high level analysis system that does deep searches following the data provided by compiler.fnl." -(local {: sym? : list? : sequence? : varg? : sym : view} (require :fennel)) +(local {: sym? : list? : sequence? : varg? : sym} (require :fennel)) (local utils (require :fennel-ls.utils)) (local state (require :fennel-ls.state)) @@ -169,7 +169,7 @@ Returns: _ (case (find-local-definition file name scope) def (search self file def.definition (stack-add-keys! stack def.keys) (or ?opts {}))))))) -(λ past? [?ast byte] +(λ _past? [?ast byte] ;; check if a byte is past an ast object (and (= (type ?ast) :table) (get-ast-info ?ast :bytestart) @@ -185,7 +185,7 @@ Returns: byte (+ 1 (utils.get-ast-info ?ast :byteend))))) -(λ does-not-contain? [?ast byte] +(λ _does-not-contain? [?ast byte] ;; check if a byte is in range of the ast (and (= (type ?ast) :table) (get-ast-info ?ast :bytestart) @@ -206,7 +206,7 @@ Returns: (if (or (sequence? ast) (list? ast)) (accumulate [(result done) nil - i child (ipairs ast) + _ child (ipairs ast) &until result] (if (contains? child byte) (recurse child byte))) @@ -219,7 +219,7 @@ Returns: (contains? value byte) (recurse value byte))))))) (values - (accumulate [result nil i top-level-form (ipairs ast) &until result] + (accumulate [result nil _ top-level-form (ipairs ast) &until result] (if (contains? top-level-form byte) (recurse top-level-form byte))) (fcollect [i 1 (length parents)] diff --git a/src/fennel-ls/state.fnl b/src/fennel-ls/state.fnl index c6dcdd8..e2dbacb 100644 --- a/src/fennel-ls/state.fnl +++ b/src/fennel-ls/state.fnl @@ -21,7 +21,7 @@ in the \"self\" object." (tset self.files uri file) file))) -(λ get-by-path [self path] +(λ _get-by-path [self path] (get-by-uri self (utils.path->uri path))) (λ get-by-module [self module] diff --git a/src/fennel-ls/utils.fnl b/src/fennel-ls/utils.fnl index 4a0808e..beb9636 100644 --- a/src/fennel-ls/utils.fnl +++ b/src/fennel-ls/utils.fnl @@ -13,7 +13,7 @@ These functions are all pure functions, which makes me happy." (λ next-lines [str nlines ?from] "Find the start of the next line from a given byte offset, or from the start of the string." (faccumulate [from (or ?from 1) - i 1 nlines] + _ 1 nlines] (next-line str from))) (fn utf [byte]