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"
|
{: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"
|
:macro-path "./?.fnl;./?/init-macros.fnl;./?/init.fnl;src/?.fnl;src/?/init-macros.fnl;src/?/init.fnl"
|
||||||
:lua-version "lua54"
|
:lua-version "lua54"
|
||||||
:libraries {:tic-80 false}
|
:libraries {:love-2d false
|
||||||
|
:tic-80 false}
|
||||||
:extra-globals ""
|
:extra-globals ""
|
||||||
:lints {:unused-definition true
|
:lints {:unused-definition true
|
||||||
:unknown-module-field true
|
:unknown-module-field true
|
||||||
|
|||||||
@ -19,7 +19,7 @@ There are no global settings. They're all stored in the `server` object.
|
|||||||
(local default-configuration
|
(local default-configuration
|
||||||
{:fennel-path (option "./?.fnl;./?/init.fnl;src/?.fnl;src/?/init.fnl")
|
{: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")
|
:macro-path (option "./?.fnl;./?/init-macros.fnl;./?/init.fnl;src/?.fnl;src/?/init-macros.fnl;src/?/init.fnl")
|
||||||
:lua-version (option "lua54")
|
:lua-version (option :lua54)
|
||||||
:lints {:unused-definition (option true)
|
:lints {:unused-definition (option true)
|
||||||
:unknown-module-field (option true)
|
:unknown-module-field (option true)
|
||||||
:unnecessary-method (option true)
|
:unnecessary-method (option true)
|
||||||
@ -27,23 +27,20 @@ There are no global settings. They're all stored in the `server` object.
|
|||||||
:var-never-set (option true)
|
:var-never-set (option true)
|
||||||
:op-with-no-arguments (option true)
|
:op-with-no-arguments (option true)
|
||||||
:multival-in-middle-of-call (option true)}
|
:multival-in-middle-of-call (option true)}
|
||||||
:libraries {:tic-80 (option false)}
|
:libraries {:love2d (option false) :tic-80 (option false)}
|
||||||
:extra-globals (option "")})
|
:extra-globals (option "")})
|
||||||
|
|
||||||
(fn make-configuration-from-template [default ?user ?parent]
|
(fn make-configuration-from-template [default ?user ?parent]
|
||||||
(if (= option-mt (getmetatable default))
|
(if (= option-mt (getmetatable default))
|
||||||
(let [setting
|
(let [setting (case-try ?user
|
||||||
(case-try ?user
|
|
||||||
nil (?. ?parent :all)
|
nil (?. ?parent :all)
|
||||||
nil (. default 1))]
|
nil (. default 1))]
|
||||||
(assert (= (type (. default 1)) (type setting)))
|
(assert (= (type (. default 1)) (type setting)))
|
||||||
setting)
|
setting)
|
||||||
(= :table (type default))
|
(= :table (type default))
|
||||||
(collect [k _ (pairs default)]
|
(collect [k _ (pairs default)]
|
||||||
k (make-configuration-from-template
|
k
|
||||||
(. default k)
|
(make-configuration-from-template (. default k) (?. ?user k) ?user))
|
||||||
(?. ?user k)
|
|
||||||
?user))
|
|
||||||
(error "This is a bug with fennel-ls: default-configuration has a key that isn't a table or option")))
|
(error "This is a bug with fennel-ls: default-configuration has a key that isn't a table or option")))
|
||||||
|
|
||||||
(λ make-configuration [?c]
|
(λ 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]
|
(λ choose-position-encoding [init-params]
|
||||||
"fennel-ls natively uses utf-8, so the goal is to choose positionEncoding=\"utf-8\".
|
"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)."
|
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)
|
(let [?position-encodings (?. init-params :capabilities :general
|
||||||
utf8?
|
:positionEncodings)
|
||||||
(if (= (type ?position-encodings) :table)
|
utf8? (if (= (type ?position-encodings) :table)
|
||||||
(accumulate [utf-8? false
|
(accumulate [utf-8? false _ encoding (ipairs ?position-encodings)
|
||||||
_ encoding (ipairs ?position-encodings)
|
|
||||||
&until utf-8?]
|
&until utf-8?]
|
||||||
(or (= encoding :utf-8)
|
(or (= encoding :utf-8) (= encoding :utf8)))
|
||||||
(= encoding :utf8)))
|
|
||||||
false)]
|
false)]
|
||||||
(if utf8?
|
(if utf8? :utf-8 :utf-16)))
|
||||||
:utf-8
|
|
||||||
:utf-16)))
|
|
||||||
|
|
||||||
(λ try-parsing [{: text : uri}]
|
(λ try-parsing [{: text : uri}]
|
||||||
(local fennel (require :fennel))
|
(local fennel (require :fennel))
|
||||||
@ -72,10 +65,10 @@ However, when not an option, fennel-ls will fall back to positionEncoding=\"utf-
|
|||||||
|
|
||||||
(λ load-config [server]
|
(λ load-config [server]
|
||||||
"This is where we can put anything that needs to react to config changes"
|
"This is where we can put anything that needs to react to config changes"
|
||||||
|
(make-configuration (when server.root-uri
|
||||||
(make-configuration
|
(-?> (files.read-file server
|
||||||
(when server.root-uri
|
(utils.path->uri (utils.path-join (utils.uri->path server.root-uri)
|
||||||
(-?> (files.read-file server (utils.path->uri (utils.path-join (utils.uri->path server.root-uri) "flsproject.fnl")))
|
:flsproject.fnl)))
|
||||||
try-parsing))))
|
try-parsing))))
|
||||||
|
|
||||||
(λ reload [server]
|
(λ reload [server]
|
||||||
@ -89,7 +82,7 @@ However, when not an option, fennel-ls will fall back to positionEncoding=\"utf-
|
|||||||
(reload server)
|
(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".
|
;; 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.
|
;; 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
|
{: initialize : reload}
|
||||||
: reload}
|
|
||||||
|
|||||||
@ -1,16 +1,15 @@
|
|||||||
(local fennel (require :fennel))
|
(local fennel (require :fennel))
|
||||||
(local {:metadata METADATA
|
(local {:metadata METADATA
|
||||||
:scopes {:global {:specials SPECIALS
|
:scopes {:global {:specials SPECIALS :macros MACROS}}}
|
||||||
:macros MACROS}}}
|
|
||||||
(require :fennel.compiler))
|
(require :fennel.compiler))
|
||||||
|
|
||||||
(local specials
|
(local specials (collect [name value (pairs SPECIALS)]
|
||||||
(collect [name value (pairs SPECIALS)]
|
name
|
||||||
name {:binding name :metadata (. METADATA value)}))
|
{:binding name :metadata (. METADATA value)}))
|
||||||
|
|
||||||
(local macros*
|
(local macros* (collect [name value (pairs MACROS)]
|
||||||
(collect [name value (pairs MACROS)]
|
name
|
||||||
name {:binding name :metadata (. METADATA value)}))
|
{:binding name :metadata (. METADATA value)}))
|
||||||
|
|
||||||
(local lua-versions
|
(local lua-versions
|
||||||
{:lua51 (require :fennel-ls.docs.generated.lua51)
|
{:lua51 (require :fennel-ls.docs.generated.lua51)
|
||||||
@ -22,17 +21,20 @@
|
|||||||
(when (not (. lua-versions version))
|
(when (not (. lua-versions version))
|
||||||
(error (.. "fennel-ls doesn't know about lua version " version "\n"
|
(error (.. "fennel-ls doesn't know about lua version " version "\n"
|
||||||
"The allowed versions are: "
|
"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))
|
(. lua-versions version))
|
||||||
|
|
||||||
(local libraries
|
(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]
|
(fn get-library [library]
|
||||||
(when (not (. libraries library))
|
(when (not (. libraries library))
|
||||||
(error (.. "fennel-ls doesn't know about library " library "\n"
|
(error (.. "fennel-ls doesn't know about library " library "\n"
|
||||||
"The builtin libraries are: "
|
"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))
|
(. libraries library))
|
||||||
|
|
||||||
(fn get-all-globals [server]
|
(fn get-all-globals [server]
|
||||||
@ -41,23 +43,18 @@
|
|||||||
(when enabled?
|
(when enabled?
|
||||||
(icollect [name (pairs (get-library library)) &into result]
|
(icollect [name (pairs (get-library library)) &into result]
|
||||||
name)))
|
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)))
|
name)))
|
||||||
|
|
||||||
(fn get-global [server global-name]
|
(fn get-global [server global-name]
|
||||||
(or
|
(or (and server.configuration.libraries.tic-80
|
||||||
(and server.configuration.libraries.tic-80
|
(. (get-library :tic-80) global-name))
|
||||||
(. (get-library :tic-80)
|
(. (get-lua-version server.configuration.lua-version) global-name)))
|
||||||
global-name))
|
|
||||||
(. (get-lua-version server.configuration.lua-version)
|
|
||||||
global-name)))
|
|
||||||
|
|
||||||
(fn get-builtin [_server builtin-name]
|
(fn get-builtin [_server builtin-name]
|
||||||
(or (. specials builtin-name)
|
(or (. specials builtin-name) (. macros* builtin-name)))
|
||||||
(. macros* builtin-name)))
|
|
||||||
|
|
||||||
;; TODO get-module-metadata
|
;; TODO get-module-metadata
|
||||||
|
|
||||||
{: get-global
|
{: get-global : get-builtin : get-all-globals}
|
||||||
: 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
|
;; 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"
|
(local docs {:_G {:binding "_G"
|
||||||
:metadata {:fnl/docstring "A global variable (not a function) that
|
:metadata {:fnl/docstring "A global variable (not a function) that
|
||||||
holds the global environment
|
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.
|
with the string `?what` describing which fields to fill in.
|
||||||
The default for `?what` is to get all information available,
|
The default for `?what` is to get all information available,
|
||||||
except the table of valid lines.
|
except the table of valid lines.
|
||||||
If present,
|
The option `\"f\"`
|
||||||
the option `\"f\"`
|
|
||||||
adds a field named `func` with the function itself.
|
adds a field named `func` with the function itself.
|
||||||
If present,
|
The option `\"L\"` adds a field named `activelines`
|
||||||
the option `\"L\"`
|
with the table of valid lines,
|
||||||
adds a field named `activelines` with the table of
|
provided the function is a Lua function.
|
||||||
valid lines.
|
If the function has no debug information,
|
||||||
|
the table is empty.
|
||||||
|
|
||||||
For instance, the expression `debug.getinfo(1,\"n\").name` returns
|
For instance, the expression `debug.getinfo(1,\"n\").name` returns
|
||||||
a name for the current function,
|
a name for the current function,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user