WIP adding Love2D configuration
This commit is contained in:
parent
e1d3b7b257
commit
0e0121825d
@ -70,7 +70,8 @@ The default `flsproject.fnl` settings are:
|
||||
{:fennel-path "./?.fnl;./?/init.fnl;src/?.fnl;src/?/init.fnl"
|
||||
:macro-path "./?.fnl;./?/init-macros.fnl;./?/init.fnl;src/?.fnl;src/?/init-macros.fnl;src/?/init.fnl"
|
||||
:lua-version "lua54"
|
||||
:libraries {:tic-80 false}
|
||||
:libraries {:love-2d false
|
||||
:tic-80 false}
|
||||
:extra-globals ""
|
||||
:lints {:unused-definition true
|
||||
:unknown-module-field true
|
||||
|
||||
@ -17,33 +17,30 @@ There are no global settings. They're all stored in the `server` object.
|
||||
(fn option [default-value] (doto [default-value] (setmetatable option-mt)))
|
||||
|
||||
(local default-configuration
|
||||
{:fennel-path (option "./?.fnl;./?/init.fnl;src/?.fnl;src/?/init.fnl")
|
||||
:macro-path (option "./?.fnl;./?/init-macros.fnl;./?/init.fnl;src/?.fnl;src/?/init-macros.fnl;src/?/init.fnl")
|
||||
:lua-version (option "lua54")
|
||||
:lints {:unused-definition (option true)
|
||||
:unknown-module-field (option true)
|
||||
:unnecessary-method (option true)
|
||||
:bad-unpack (option true)
|
||||
:var-never-set (option true)
|
||||
:op-with-no-arguments (option true)
|
||||
:multival-in-middle-of-call (option true)}
|
||||
:libraries {:tic-80 (option false)}
|
||||
:extra-globals (option "")})
|
||||
{:fennel-path (option "./?.fnl;./?/init.fnl;src/?.fnl;src/?/init.fnl")
|
||||
:macro-path (option "./?.fnl;./?/init-macros.fnl;./?/init.fnl;src/?.fnl;src/?/init-macros.fnl;src/?/init.fnl")
|
||||
:lua-version (option :lua54)
|
||||
:lints {:unused-definition (option true)
|
||||
:unknown-module-field (option true)
|
||||
:unnecessary-method (option true)
|
||||
:bad-unpack (option true)
|
||||
:var-never-set (option true)
|
||||
:op-with-no-arguments (option true)
|
||||
:multival-in-middle-of-call (option true)}
|
||||
:libraries {:love2d (option false) :tic-80 (option false)}
|
||||
:extra-globals (option "")})
|
||||
|
||||
(fn make-configuration-from-template [default ?user ?parent]
|
||||
(if (= option-mt (getmetatable default))
|
||||
(let [setting
|
||||
(case-try ?user
|
||||
nil (?. ?parent :all)
|
||||
nil (. default 1))]
|
||||
(let [setting (case-try ?user
|
||||
nil (?. ?parent :all)
|
||||
nil (. default 1))]
|
||||
(assert (= (type (. default 1)) (type setting)))
|
||||
setting)
|
||||
(= :table (type default))
|
||||
(collect [k _ (pairs default)]
|
||||
k (make-configuration-from-template
|
||||
(. default k)
|
||||
(?. ?user k)
|
||||
?user))
|
||||
k
|
||||
(make-configuration-from-template (. default k) (?. ?user k) ?user))
|
||||
(error "This is a bug with fennel-ls: default-configuration has a key that isn't a table or option")))
|
||||
|
||||
(λ make-configuration [?c]
|
||||
@ -52,18 +49,14 @@ There are no global settings. They're all stored in the `server` object.
|
||||
(λ choose-position-encoding [init-params]
|
||||
"fennel-ls natively uses utf-8, so the goal is to choose positionEncoding=\"utf-8\".
|
||||
However, when not an option, fennel-ls will fall back to positionEncoding=\"utf-16\" (with a performance hit)."
|
||||
(let [?position-encodings (?. init-params :capabilities :general :positionEncodings)
|
||||
utf8?
|
||||
(if (= (type ?position-encodings) :table)
|
||||
(accumulate [utf-8? false
|
||||
_ encoding (ipairs ?position-encodings)
|
||||
&until utf-8?]
|
||||
(or (= encoding :utf-8)
|
||||
(= encoding :utf8)))
|
||||
false)]
|
||||
(if utf8?
|
||||
:utf-8
|
||||
:utf-16)))
|
||||
(let [?position-encodings (?. init-params :capabilities :general
|
||||
:positionEncodings)
|
||||
utf8? (if (= (type ?position-encodings) :table)
|
||||
(accumulate [utf-8? false _ encoding (ipairs ?position-encodings)
|
||||
&until utf-8?]
|
||||
(or (= encoding :utf-8) (= encoding :utf8)))
|
||||
false)]
|
||||
(if utf8? :utf-8 :utf-16)))
|
||||
|
||||
(λ try-parsing [{: text : uri}]
|
||||
(local fennel (require :fennel))
|
||||
@ -72,11 +65,11 @@ However, when not an option, fennel-ls will fall back to positionEncoding=\"utf-
|
||||
|
||||
(λ load-config [server]
|
||||
"This is where we can put anything that needs to react to config changes"
|
||||
|
||||
(make-configuration
|
||||
(when server.root-uri
|
||||
(-?> (files.read-file server (utils.path->uri (utils.path-join (utils.uri->path server.root-uri) "flsproject.fnl")))
|
||||
try-parsing))))
|
||||
(make-configuration (when server.root-uri
|
||||
(-?> (files.read-file server
|
||||
(utils.path->uri (utils.path-join (utils.uri->path server.root-uri)
|
||||
:flsproject.fnl)))
|
||||
try-parsing))))
|
||||
|
||||
(λ reload [server]
|
||||
(set server.configuration (load-config server)))
|
||||
@ -89,7 +82,7 @@ However, when not an option, fennel-ls will fall back to positionEncoding=\"utf-
|
||||
(reload server)
|
||||
;; Eglot does completions differently than every other client I've seen so far, in that it considers foo.bar to be one "symbol".
|
||||
;; If the user types `foo.b`, every other client accepts `bar` as a completion, bun eglot wants the full `foo.bar` symbol.
|
||||
(set server.EGLOT_COMPLETION_QUIRK_MODE (= (?. params :clientInfo :name) :Eglot)))
|
||||
(set server.EGLOT_COMPLETION_QUIRK_MODE
|
||||
(= (?. params :clientInfo :name) :Eglot)))
|
||||
|
||||
{: initialize
|
||||
: reload}
|
||||
{: initialize : reload}
|
||||
|
||||
@ -1,38 +1,40 @@
|
||||
(local fennel (require :fennel))
|
||||
(local {:metadata METADATA
|
||||
:scopes {:global {:specials SPECIALS
|
||||
:macros MACROS}}}
|
||||
(require :fennel.compiler))
|
||||
:scopes {:global {:specials SPECIALS :macros MACROS}}}
|
||||
(require :fennel.compiler))
|
||||
|
||||
(local specials
|
||||
(collect [name value (pairs SPECIALS)]
|
||||
name {:binding name :metadata (. METADATA value)}))
|
||||
(local specials (collect [name value (pairs SPECIALS)]
|
||||
name
|
||||
{:binding name :metadata (. METADATA value)}))
|
||||
|
||||
(local macros*
|
||||
(collect [name value (pairs MACROS)]
|
||||
name {:binding name :metadata (. METADATA value)}))
|
||||
(local macros* (collect [name value (pairs MACROS)]
|
||||
name
|
||||
{:binding name :metadata (. METADATA value)}))
|
||||
|
||||
(local lua-versions
|
||||
{:lua51 (require :fennel-ls.docs.generated.lua51)
|
||||
:lua52 (require :fennel-ls.docs.generated.lua52)
|
||||
:lua53 (require :fennel-ls.docs.generated.lua53)
|
||||
:lua54 (require :fennel-ls.docs.generated.lua54)})
|
||||
{:lua51 (require :fennel-ls.docs.generated.lua51)
|
||||
:lua52 (require :fennel-ls.docs.generated.lua52)
|
||||
:lua53 (require :fennel-ls.docs.generated.lua53)
|
||||
:lua54 (require :fennel-ls.docs.generated.lua54)})
|
||||
|
||||
(fn get-lua-version [version]
|
||||
(when (not (. lua-versions version))
|
||||
(error (.. "fennel-ls doesn't know about lua version " version "\n"
|
||||
"The allowed versions are: "
|
||||
(fennel.view (doto (icollect [key (pairs lua-versions)] key) table.sort)))))
|
||||
(fennel.view (doto (icollect [key (pairs lua-versions)] key)
|
||||
table.sort)))))
|
||||
(. lua-versions version))
|
||||
|
||||
(local libraries
|
||||
{:tic-80 (require :fennel-ls.docs.generated.tic80)})
|
||||
{:love-2d (require :fennel-ls.docs.generated.love2d)
|
||||
:tic-80 (require :fennel-ls.docs.generated.tic80)})
|
||||
|
||||
(fn get-library [library]
|
||||
(when (not (. libraries library))
|
||||
(error (.. "fennel-ls doesn't know about library " library "\n"
|
||||
"The builtin libraries are: "
|
||||
(fennel.view (doto (icollect [key (pairs libraries)] key) table.sort)))))
|
||||
(fennel.view (doto (icollect [key (pairs libraries)] key)
|
||||
table.sort)))))
|
||||
(. libraries library))
|
||||
|
||||
(fn get-all-globals [server]
|
||||
@ -41,23 +43,18 @@
|
||||
(when enabled?
|
||||
(icollect [name (pairs (get-library library)) &into result]
|
||||
name)))
|
||||
(icollect [name (pairs (get-lua-version server.configuration.lua-version)) &into result]
|
||||
(icollect [name (pairs (get-lua-version server.configuration.lua-version))
|
||||
&into result]
|
||||
name)))
|
||||
|
||||
(fn get-global [server global-name]
|
||||
(or
|
||||
(and server.configuration.libraries.tic-80
|
||||
(. (get-library :tic-80)
|
||||
global-name))
|
||||
(. (get-lua-version server.configuration.lua-version)
|
||||
global-name)))
|
||||
(or (and server.configuration.libraries.tic-80
|
||||
(. (get-library :tic-80) global-name))
|
||||
(. (get-lua-version server.configuration.lua-version) global-name)))
|
||||
|
||||
(fn get-builtin [_server builtin-name]
|
||||
(or (. specials builtin-name)
|
||||
(. macros* builtin-name)))
|
||||
(or (. specials builtin-name) (. macros* builtin-name)))
|
||||
|
||||
;; TODO get-module-metadata
|
||||
|
||||
{: get-global
|
||||
: get-builtin
|
||||
: get-all-globals}
|
||||
{: get-global : get-builtin : get-all-globals}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
;; auto-generated by `make docs` from fennel-ls. Contents come from https://www.lua.org/manual/5.4/manual.html
|
||||
;; Lua Lua 5.4 Reference Manual last updated Tue May 2 20:09:38 UTC 2023
|
||||
;; Lua Lua 5.4 Reference Manual last updated Thu Jun 13 22:15:52 UTC 2024
|
||||
(local docs {:_G {:binding "_G"
|
||||
:metadata {:fnl/docstring "A global variable (not a function) that
|
||||
holds the global environment
|
||||
@ -223,13 +223,13 @@ The returned table can contain all the fields returned by `lua_getinfo`,
|
||||
with the string `?what` describing which fields to fill in.
|
||||
The default for `?what` is to get all information available,
|
||||
except the table of valid lines.
|
||||
If present,
|
||||
the option `\"f\"`
|
||||
The option `\"f\"`
|
||||
adds a field named `func` with the function itself.
|
||||
If present,
|
||||
the option `\"L\"`
|
||||
adds a field named `activelines` with the table of
|
||||
valid lines.
|
||||
The option `\"L\"` adds a field named `activelines`
|
||||
with the table of valid lines,
|
||||
provided the function is a Lua function.
|
||||
If the function has no debug information,
|
||||
the table is empty.
|
||||
|
||||
For instance, the expression `debug.getinfo(1,\"n\").name` returns
|
||||
a name for the current function,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user