From d23d36a41452085dfb1ad31bdc91ef80a829a8d7 Mon Sep 17 00:00:00 2001 From: Phil Hagelberg Date: Wed, 26 Feb 2025 23:09:11 -0800 Subject: [PATCH] Support :union as lua-version setting. --- changelog.md | 1 + docs/manual.md | 2 +- src/fennel-ls.fnl | 1 - src/fennel-ls/config.fnl | 2 -- src/fennel-ls/docs.fnl | 7 ++++++- test/diagnostic.fnl | 7 ++++++- 6 files changed, 14 insertions(+), 6 deletions(-) diff --git a/changelog.md b/changelog.md index ab5f702..8e9f236 100644 --- a/changelog.md +++ b/changelog.md @@ -4,6 +4,7 @@ ### Features * Support `:lua-version` settings like `"lua5.4"` rather than requiring `"lua54"`. +* Support `"union"` in `:lua-version` for globals present in any Lua version. * Support `"intersection"` in `:lua-version` for globals present in every Lua version. * Show the kind of thing being completed better. * Add lints for unnecessary `tset` and `do`. diff --git a/docs/manual.md b/docs/manual.md index 5d6ad2e..246505b 100644 --- a/docs/manual.md +++ b/docs/manual.md @@ -119,7 +119,7 @@ The default `flsproject.fnl` settings are: extra-globals: Space separated list of allowed global identifiers; in addition to a set of predefined lua globals. -version: One of lua51, lua52, lua53, or lua54. +version: One of lua51, lua52, lua53, lua54, intersection, or union. libraries: This setting controls which extra documentation fennel-ls can load in to your environment. I've only done this for tic-80 for now. diff --git a/src/fennel-ls.fnl b/src/fennel-ls.fnl index e42b64a..69259e2 100644 --- a/src/fennel-ls.fnl +++ b/src/fennel-ls.fnl @@ -20,7 +20,6 @@ :method "initialize" :params {:capabilities {:general {:positionEncodings [:utf-8]}} :clientInfo {:name "fennel-ls"} - ; don't think this is a valid URI, but I want to operate in the current directory :rootUri "file://."}}))] (var should-err? false) (each [_ filename (ipairs filenames)] diff --git a/src/fennel-ls/config.fnl b/src/fennel-ls/config.fnl index 25fd876..5bea403 100644 --- a/src/fennel-ls/config.fnl +++ b/src/fennel-ls/config.fnl @@ -7,8 +7,6 @@ There are no global settings. They're all stored in the `server` object. ;; TODO: Settings to set the warning levels of lints ;; Setting to allow all globals -;; Have an option for "union of all lua versions" lua version. -;; Have an option for "intersection of all lua versions", ie disallow using (unpack) without saying (or table.unpack _G.unpack). (local files (require :fennel-ls.files)) (local utils (require :fennel-ls.utils)) diff --git a/src/fennel-ls/docs.fnl b/src/fennel-ls/docs.fnl index bdb510e..e8c7860 100644 --- a/src/fennel-ls/docs.fnl +++ b/src/fennel-ls/docs.fnl @@ -21,7 +21,8 @@ {:lua5.1 (require :fennel-ls.docs.generated.lua51) :lua5.2 (require :fennel-ls.docs.generated.lua52) :lua5.3 (require :fennel-ls.docs.generated.lua53) - :lua5.4 (require :fennel-ls.docs.generated.lua54)}) + :lua5.4 (require :fennel-ls.docs.generated.lua54) + :union {}}) ;; aliases (set lua-versions.lua51 (. lua-versions "lua5.1")) @@ -41,6 +42,10 @@ (set lua-versions.lua51.package.fields.config lua-versions.lua52.package.fields.config) +(each [_ version (pairs lua-versions)] + (each [k v (pairs version)] + (set (. lua-versions.union k) v))) + (set lua-versions.intersection (collect [k v (pairs lua-versions.lua51)] (if (. lua-versions.lua54 k) (values k v)))) diff --git a/test/diagnostic.fnl b/test/diagnostic.fnl index 56dcf4b..b2e42c2 100644 --- a/test/diagnostic.fnl +++ b/test/diagnostic.fnl @@ -150,7 +150,12 @@ (check "(print (unpack [_VERSION]))" [{:message "unknown identifier: unpack"}] [{:message "unknown identifier: _VERSION"}] - {:lua-version "intersection"})) + {:lua-version "intersection"}) + (check "(warn (unpack [_VERSION]))" + [] + [{:message "unknown identifier: unpack"} + {:message "unknown identifier: warn"}] + {:lua-version "union"})) {: test-lua-versions : test-compile-error