From 9b54f882c9e5c08e65363d5bce3fb7eb0e298f0e Mon Sep 17 00:00:00 2001 From: Phil Hagelberg Date: Wed, 26 Feb 2025 22:41:59 -0800 Subject: [PATCH] Add tests for tic80 docset and fake external docset. --- Makefile | 30 +++++++++++++++++------- src/fennel-ls/compiler.fnl | 2 +- test/data/fennel-ls/docsets/external.lua | 8 +++++++ test/hover.fnl | 15 +++++++++--- 4 files changed, 43 insertions(+), 12 deletions(-) create mode 100644 test/data/fennel-ls/docsets/external.lua diff --git a/Makefile b/Makefile index d3b3f8a..6f06c8d 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,8 @@ BINDIR ?= $(PREFIX)/bin FENNELFLAGS=--add-package-path "deps/?.lua" --add-fennel-path "src/?.fnl;deps/?.fnl" REQUIRE_AS_INCLUDE_SETTINGS=$(shell $(FENNEL) tools/require-flags.fnl) -ROCKSPEC_LATEST_SCM=rockspecs/fennel-ls-scm-$(shell ls rockspecs | grep -Eo 'scm-[0-9]+' | grep -Eo [0-9]+ | sort -n | tail -1).rockspec +ROCKSPEC_LATEST_SCM=rockspecs/fennel-ls-scm-$(shell ls rockspecs | \ + grep -Eo 'scm-[0-9]+' | grep -Eo [0-9]+ | sort -n | tail -1).rockspec .PHONY: all clean test repl install docs docs-love2d install-deps ci selflint \ deps rm-docs rm-deps count testall check-deps check-luarocks @@ -22,18 +23,31 @@ all: $(EXE) $(EXE): $(SRC) echo "#!/usr/bin/env $(LUA)" > $@ - $(FENNEL) $(FENNELFLAGS) $(REQUIRE_AS_INCLUDE_SETTINGS) --require-as-include --compile src/fennel-ls.fnl >> $@ + $(FENNEL) $(FENNELFLAGS) $(REQUIRE_AS_INCLUDE_SETTINGS) --require-as-include \ + --compile src/fennel-ls.fnl >> $@ chmod 755 $@ -repl: - $(FENNEL) $(FENNELFLAGS) +install: $(EXE) + mkdir -p $(DESTDIR)$(BINDIR) && cp $< $(DESTDIR)$(BINDIR)/ + +## Generating docs docs: $(FENNEL) $(FENNELFLAGS) tools/get-docs.fnl $(GET_DOCS_FLAGS) -docs-love2d: +XDG_DATA_HOME ?= $(HOME)/.local/share +DOCSET_DIR = $(XDG_DATA_HOME)/fennel-ls/docsets/ + +$(DOCSET_DIR)/love2d.lua: src/fennel-ls/docs/generated/love2d.fnl + mkdir -p $(DOCSET_DIR) + $(FENNEL) $(FENNELFLAGS) --compile $< > $@ + +src/fennel-ls/docs/generated/love2d.fnl: $(FENNEL) $(FENNELFLAGS) tools/get-docs.fnl --generate-love2d +# has to be separate for licensing reasons +docs-love2d: $(DOCSET_DIR)/love2d.lua + rm-docs: rm -rf src/fennel-ls/docs/ @@ -49,13 +63,13 @@ selflint: count: cloc $(shell find src -name "*.fnl" | grep -v "generated") -install: $(EXE) - mkdir -p $(DESTDIR)$(BINDIR) && cp $< $(DESTDIR)$(BINDIR)/ +repl: + DEV=y $(FENNEL) $(FENNELFLAGS) # to run one module: make test FAITH_TEST=test.lint # to run one test: make test FAITH_TEST="test.lint test-unset-var" test: $(EXE) - TESTING=1 $(FENNEL) $(FENNELFLAGS) test/init.fnl + DEV=y XDG_DATA_HOME=test/data $(FENNEL) $(FENNELFLAGS) test/init.fnl testall: $(MAKE) test LUA=lua5.1 diff --git a/src/fennel-ls/compiler.fnl b/src/fennel-ls/compiler.fnl index abfed64..f571564 100644 --- a/src/fennel-ls/compiler.fnl +++ b/src/fennel-ls/compiler.fnl @@ -350,7 +350,7 @@ identifiers are declared / referenced in which places." (case ... (true ?item1 ?item2) (values ?item1 ?item2) (where (or (nil err) (false err)) (not (err:find "^[^\n]-__NOT_AN_ERROR\n"))) - (if (os.getenv :TESTING) + (if (os.getenv :DEV) (error (.. "\nYou have crashed fennel-ls (or the fennel " component ") with the following message\n:" err "\n\n^^^ the error message above here is the root problem\n\n")) (table.insert diagnostics diff --git a/test/data/fennel-ls/docsets/external.lua b/test/data/fennel-ls/docsets/external.lua new file mode 100644 index 0000000..020724f --- /dev/null +++ b/test/data/fennel-ls/docsets/external.lua @@ -0,0 +1,8 @@ +-- a fake external docset +return {translate = { binding = "translate", + metadata = { + ["fls/itemKind"] = "Function", + ["fnl/arglist"] = {"str", "from", "to"}, + ["fnl/docstring"] = "convert from one lanugage to another" + } +}} diff --git a/test/hover.fnl b/test/hover.fnl index 2555bf8..2d76d0f 100644 --- a/test/hover.fnl +++ b/test/hover.fnl @@ -3,8 +3,8 @@ (local {: create-client} (require :test.utils)) (local {: null} (require :dkjson)) -(fn check [file-contents ?response-string] - (let [{: client : uri : cursor} (create-client file-contents) +(fn check [file-contents ?response-string ?opts] + (let [{: client : uri : cursor} (create-client file-contents nil ?opts) [message] (client:hover uri cursor)] (if (= (type ?response-string) :string) (faith.= ?response-string (?. message :result :contents :value) @@ -178,6 +178,14 @@ except that it sets a new message handler `msgh`.") #($:find "```fnl\n(quote x)\n```" 1 true)) nil) +(fn test-libraries [] + (check "#(trac|e :hello)" + #($:find "a service function") + {:libraries {:tic80 true}}) + (check "(trans|late \"hello\" :en :zh)" + #($:find "convert from one lanugage to another") + {:libraries {:external true}})) + {: test-literals : test-builtins : test-globals @@ -187,4 +195,5 @@ except that it sets a new message handler `msgh`.") : test-crash : test-multival : test-macro - : test-reader} + : test-reader + : test-libraries}