Support :union as lua-version setting.

This commit is contained in:
Phil Hagelberg 2025-02-26 23:09:11 -08:00
parent 0d7e9b6183
commit d23d36a414
6 changed files with 14 additions and 6 deletions

View File

@ -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`.

View File

@ -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.

View File

@ -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)]

View File

@ -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))

View File

@ -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))))

View File

@ -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