refactoring

This commit is contained in:
XeroOl 2024-07-07 14:31:22 -05:00
parent caab3ebfd1
commit b0b91a4fd4
4 changed files with 13 additions and 33 deletions

View File

@ -313,8 +313,9 @@ identifiers are declared / referenced in which places."
(error "__NOT_AN_ERROR")))) (error "__NOT_AN_ERROR"))))
(local allowed-globals (docs.get-all-globals server)) (local allowed-globals (docs.get-all-globals server))
(each [_ v (ipairs (utils.split-spaces server.configuration.extra-globals))] (icollect [extra-global (server.configuration.extra-globals:gmatch "[^ ]+")
(table.insert allowed-globals v)) &into allowed-globals]
extra-global)
(fn parse-ast [parser] (fn parse-ast [parser]
(icollect [ok ast parser &until (not ok)] ast)) (icollect [ok ast parser &until (not ok)] ast))

View File

@ -5,7 +5,6 @@ user code. Fennel-ls doesn't support user-code formatting as of now."
(local {: sym? (local {: sym?
: view} (require :fennel)) : view} (require :fennel))
(local {: type=} (require :fennel-ls.utils))
(λ code-block [str] (λ code-block [str]
(.. "```fnl\n" str "\n```")) (.. "```fnl\n" str "\n```"))
@ -57,26 +56,26 @@ fntype is one of fn or λ or lambda"
body body
(fn? fntype) (fn? fntype)
(sym? name) (sym? name)
(type= arglist :table) (= (type arglist) :table)
(type= docstring :string)) (= (type docstring) :string))
{: fntype : name : arglist : docstring} {: fntype : name : arglist : docstring}
;; docstring ;; docstring
(where [fntype arglist docstring body] (where [fntype arglist docstring body]
body body
(fn? fntype) (fn? fntype)
(type= arglist :table) (= (type arglist) :table)
(type= docstring :string)) (= (type docstring) :string))
{: fntype : arglist : docstring} {: fntype : arglist : docstring}
;; name ;; name
(where [fntype name arglist] (where [fntype name arglist]
(fn? fntype) (fn? fntype)
(sym? name) (sym? name)
(type= arglist :table)) (= (type arglist) :table))
{: fntype : name : arglist} {: fntype : name : arglist}
;; none ;; none
(where [fntype arglist] (where [fntype arglist]
(fn? fntype) (fn? fntype)
(type= arglist :table)) (= (type arglist) :table))
{: fntype : arglist})) {: fntype : arglist}))
(λ hover-format [result] (λ hover-format [result]

View File

@ -176,22 +176,13 @@ WARNING: this is only used in the test code, not in the real language server"
symbol symbol
(pick-values 1 (symbol:match "[^.:]*")))) (pick-values 1 (symbol:match "[^.:]*"))))
(λ type= [val typ]
(= (type val) typ))
(λ uniq-by [list key-fn] (λ uniq-by [list key-fn]
(let [result [] (let [seen {}]
seen {}] (icollect [_ new-item (ipairs list)]
(each [_ new-item (ipairs list)]
(let [key (key-fn new-item)] (let [key (key-fn new-item)]
(when (not (. seen key)) (when (not (. seen key))
(tset seen key true) (tset seen key true)
(table.insert result new-item)))) new-item)))))
result))
(λ split-spaces [str]
(icollect [m (str:gmatch "[^ ]+")]
m))
(local path-sep (package.config:sub 1 1)) (local path-sep (package.config:sub 1 1))
@ -226,8 +217,6 @@ WARNING: this is only used in the test code, not in the real language server"
: multi-sym-base : multi-sym-base
: get-ast-info : get-ast-info
: uniq-by : uniq-by
: type=
: split-spaces
: absolute-path? : absolute-path?
: path-join : path-join
: path-sep : path-sep

View File

@ -43,15 +43,6 @@
(create-client "(let [map {}] (set (. map (tostring :a)) :b))") (create-client "(let [map {}] (set (. map (tostring :a)) :b))")
nil) nil)
(fn test-split-spaces []
(faith.= [] (utils.split-spaces ""))
(faith.= ["foo"] (utils.split-spaces "foo"))
(faith.= ["foo"] (utils.split-spaces " foo "))
(faith.= ["foo-bar" "bar" "baz"] (utils.split-spaces "foo-bar bar baz"))
(faith.= ["foo-bar" "bar" "baz"] (utils.split-spaces " foo-bar bar baz "))
nil)
{: test-multi-sym-split {: test-multi-sym-split
: test-find-symbol : test-find-symbol
: test-failure : test-failure}
: test-split-spaces}