Somehow even more refactoring

This commit is contained in:
XeroOl 2022-08-09 01:20:58 -05:00
parent e57833f1e5
commit 44e7158e7d
No known key found for this signature in database
GPG Key ID: 9DD4B4B4DAED0322
8 changed files with 531 additions and 6185 deletions

5686
fennel.lua

File diff suppressed because it is too large Load Diff

View File

@ -110,14 +110,15 @@
:call call
:destructure define})
(local filename file.uri)
(local ast
(icollect [ok ast (fennel.parser file.text)]
(icollect [ok ast (fennel.parser file.text filename)]
ast))
(local scope (fennel.scope))
(each [_i form (ipairs ast)]
(fennel.compile form
{:filename file.uri
{: filename
: scope
:plugins [plugin]}))

View File

@ -64,9 +64,9 @@ Every time the client sends a message, it gets handled by a function in the corr
(match (language.find-symbol file.ast byte)
symbol
(match (language.search-symbol self file symbol [])
definition
{:range (message.range file.text definition)
:uri uri})))
(definition result-file) ;; curse you, magical match rules
(message.range-and-uri definition result-file))))
(λ notifications.textDocument/didChange [self send {: contentChanges :textDocument {: uri}}]
(local file (state.get-by-uri self uri))
(assert file.open?)

View File

@ -17,7 +17,8 @@
(set search-assignment
(λ search-assignment [self file binding ?definition stack]
(if (= 0 (length stack))
binding
(values binding file) ;; BASE CASE!!
;; TODO sift down the binding
(search self file ?definition stack))))
@ -28,7 +29,7 @@
(table.insert stack (. split i))))
(match (. file.references symbol)
to (search-assignment self file to.binding to.definition stack)
nil nil)))
nil nil))) ;; BASE CASE: Give up
(set search
(λ search [self file item stack]
@ -36,7 +37,7 @@
(fennelutils.table? item)
(if (. item (. stack (length stack)))
(search self file (. item (table.remove stack)) stack)
nil)
nil) ;; BASE CASE: Give up
(sym? item)
(search-symbol self file item stack)
;; TODO
@ -45,7 +46,6 @@
[-require- mod]
(let [newfile (state.get-by-module self mod)
newitem (. newfile.ast (length newfile.ast))]
(print newfile.uri mod)
(search self newfile newitem stack))
_ (error (.. "I don't know what to do with " (fennel.view item)))))))

View File

@ -7,6 +7,7 @@ missing fields with null fields, and I want to have one location
to look to fix this in the future."
(local utils (require :fennel-ls.utils))
(local state (require :fennel-ls.state))
(local error-codes
{;; JSON-RPC errors
@ -46,18 +47,21 @@ to look to fix this in the future."
: id
:result ?result})
(λ range [text ?ast]
"create a LSP range representing the span of an AST object"
(if (= (type ?ast) :table)
(match (values (utils.get-ast-info ?ast :bytestart) (utils.get-ast-info ?ast :byteend))
(λ range-and-uri [?ast file]
"if possible, returns the location of a symbol"
(match
(values
(utils.get-ast-info ?ast :bytestart)
(utils.get-ast-info ?ast :byteend))
(i j)
(let [(start-line start-col) (utils.byte->pos text i)
(end-line end-col) (utils.byte->pos text (+ j 1))]
{:start {:line start-line :character start-col}
:end {:line end-line :character end-col}}))))
(let [(start-line start-col) (utils.byte->pos file.text i)
(end-line end-col) (utils.byte->pos file.text (+ j 1))]
{:range {:start {:line start-line :character start-col}
:end {:line end-line :character end-col}}
:uri file.uri})))
{: create-notification
: create-request
: create-response
: create-error
: range}
: range-and-uri}

View File

@ -20,6 +20,10 @@
(tset self.files uri file)
file)))
(λ get-by-path [self path]
(get-by-uri (utils.path->uri path)))
(λ get-by-module [self module]
;; check the cache
(match (. self.modules module)
@ -38,14 +42,16 @@
(error (.. "cannot find module " module)))))
(λ set-uri-contents [self uri text]
(if (. self.files uri)
(match (. self.files uri)
;; modify existing file
(let [file (. self.files uri)]
file
(when (not= text file.text)
(set file.text text)
(compile file)
file))
file)
;; create new file
nil
(let [file {: uri : text}]
(tset self.files uri file)
(compile file)

File diff suppressed because it is too large Load Diff

View File

@ -49,17 +49,21 @@
(it "can go to a function inside a table"
(check "example.fnl" 28 6 "example.fnl" 4 4 4 7))
(it "handles (local _ (require XXX))"
(check "example.fnl" 0 10 "foo.fnl" 0 0 0 0))
(it "can go to a function in another file when accessed by multisym"
(check "example.fnl" 7 7 "foo.fnl" 2 4 2 13)))
(it "handles (require XXX))"
(check "example.fnl" 1 5 "bar.fnl" 0 0 0 0)))
;; (it "goes further if you go to definition on a binding")
;; (it "handles (local _ (require XXX))")
;; (check "example.fnl" 0 10 "foo.fnl" 0 0 0 0)
;; (it "works directly on a require/include (require XXX))"
;; (check "example.fnl" 1 5 "bar.fnl" 0 0 0 0))
;; (it "can go to a field inside of a table")
;; (it "can go to a destructured function argument")
;; (it "can go to a reference that occurs in a macro")
;; (it "doesn't have ghost definitions from the same byte ranges as the macro files it's using")
;; (it "can go to a function in another file when accessed by multisym")
;; (it "can go to a function in another file imported via destructuring assignment")
;; (it "can work with a custom fennelpath")
;; (it "can go through more than one extra file")
@ -68,3 +72,5 @@
;; (it "finds the definition of macros")
;; (it "can follow import-macros")
;; (it "can go to the definition even in a lua file")
;; (it "can go to a function's arguments when they're available")