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 :call call
:destructure define}) :destructure define})
(local filename file.uri)
(local ast (local ast
(icollect [ok ast (fennel.parser file.text)] (icollect [ok ast (fennel.parser file.text filename)]
ast)) ast))
(local scope (fennel.scope)) (local scope (fennel.scope))
(each [_i form (ipairs ast)] (each [_i form (ipairs ast)]
(fennel.compile form (fennel.compile form
{:filename file.uri {: filename
: scope : scope
:plugins [plugin]})) :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) (match (language.find-symbol file.ast byte)
symbol symbol
(match (language.search-symbol self file symbol []) (match (language.search-symbol self file symbol [])
definition (definition result-file) ;; curse you, magical match rules
{:range (message.range file.text definition) (message.range-and-uri definition result-file))))
:uri uri})))
(λ notifications.textDocument/didChange [self send {: contentChanges :textDocument {: uri}}] (λ notifications.textDocument/didChange [self send {: contentChanges :textDocument {: uri}}]
(local file (state.get-by-uri self uri)) (local file (state.get-by-uri self uri))
(assert file.open?) (assert file.open?)

View File

@ -17,7 +17,8 @@
(set search-assignment (set search-assignment
(λ search-assignment [self file binding ?definition stack] (λ search-assignment [self file binding ?definition stack]
(if (= 0 (length stack)) (if (= 0 (length stack))
binding (values binding file) ;; BASE CASE!!
;; TODO sift down the binding ;; TODO sift down the binding
(search self file ?definition stack)))) (search self file ?definition stack))))
@ -28,7 +29,7 @@
(table.insert stack (. split i)))) (table.insert stack (. split i))))
(match (. file.references symbol) (match (. file.references symbol)
to (search-assignment self file to.binding to.definition stack) to (search-assignment self file to.binding to.definition stack)
nil nil))) nil nil))) ;; BASE CASE: Give up
(set search (set search
(λ search [self file item stack] (λ search [self file item stack]
@ -36,7 +37,7 @@
(fennelutils.table? item) (fennelutils.table? item)
(if (. item (. stack (length stack))) (if (. item (. stack (length stack)))
(search self file (. item (table.remove stack)) stack) (search self file (. item (table.remove stack)) stack)
nil) nil) ;; BASE CASE: Give up
(sym? item) (sym? item)
(search-symbol self file item stack) (search-symbol self file item stack)
;; TODO ;; TODO
@ -45,7 +46,6 @@
[-require- mod] [-require- mod]
(let [newfile (state.get-by-module self mod) (let [newfile (state.get-by-module self mod)
newitem (. newfile.ast (length newfile.ast))] newitem (. newfile.ast (length newfile.ast))]
(print newfile.uri mod)
(search self newfile newitem stack)) (search self newfile newitem stack))
_ (error (.. "I don't know what to do with " (fennel.view item))))))) _ (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." to look to fix this in the future."
(local utils (require :fennel-ls.utils)) (local utils (require :fennel-ls.utils))
(local state (require :fennel-ls.state))
(local error-codes (local error-codes
{;; JSON-RPC errors {;; JSON-RPC errors
@ -46,18 +47,21 @@ to look to fix this in the future."
: id : id
:result ?result}) :result ?result})
(λ range [text ?ast] (λ range-and-uri [?ast file]
"create a LSP range representing the span of an AST object" "if possible, returns the location of a symbol"
(if (= (type ?ast) :table) (match
(match (values (utils.get-ast-info ?ast :bytestart) (utils.get-ast-info ?ast :byteend)) (values
(i j) (utils.get-ast-info ?ast :bytestart)
(let [(start-line start-col) (utils.byte->pos text i) (utils.get-ast-info ?ast :byteend))
(end-line end-col) (utils.byte->pos text (+ j 1))] (i j)
{:start {:line start-line :character start-col} (let [(start-line start-col) (utils.byte->pos file.text i)
:end {:line end-line :character end-col}})))) (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-notification
: create-request : create-request
: create-response : create-response
: create-error : create-error
: range} : range-and-uri}

View File

@ -20,6 +20,10 @@
(tset self.files uri file) (tset self.files uri file)
file))) file)))
(λ get-by-path [self path]
(get-by-uri (utils.path->uri path)))
(λ get-by-module [self module] (λ get-by-module [self module]
;; check the cache ;; check the cache
(match (. self.modules module) (match (. self.modules module)
@ -38,14 +42,16 @@
(error (.. "cannot find module " module))))) (error (.. "cannot find module " module)))))
(λ set-uri-contents [self uri text] (λ set-uri-contents [self uri text]
(if (. self.files uri) (match (. self.files uri)
;; modify existing file ;; modify existing file
(let [file (. self.files uri)] file
(when (not= text file.text) (when (not= text file.text)
(set file.text text) (set file.text text)
(compile file) (compile file)
file)) file)
;; create new file ;; create new file
nil
(let [file {: uri : text}] (let [file {: uri : text}]
(tset self.files uri file) (tset self.files uri file)
(compile 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" (it "can go to a function inside a table"
(check "example.fnl" 28 6 "example.fnl" 4 4 4 7)) (check "example.fnl" 28 6 "example.fnl" 4 4 4 7))
(it "handles (local _ (require XXX))" (it "can go to a function in another file when accessed by multisym"
(check "example.fnl" 0 10 "foo.fnl" 0 0 0 0)) (check "example.fnl" 7 7 "foo.fnl" 2 4 2 13)))
(it "handles (require XXX))" ;; (it "goes further if you go to definition on a binding")
(check "example.fnl" 1 5 "bar.fnl" 0 0 0 0)))
;; (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 field inside of a table")
;; (it "can go to a destructured function argument") ;; (it "can go to a destructured function argument")
;; (it "can go to a reference that occurs in a macro") ;; (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 "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 go to a function in another file imported via destructuring assignment")
;; (it "can work with a custom fennelpath") ;; (it "can work with a custom fennelpath")
;; (it "can go through more than one extra file") ;; (it "can go through more than one extra file")
@ -68,3 +72,5 @@
;; (it "finds the definition of macros") ;; (it "finds the definition of macros")
;; (it "can follow import-macros") ;; (it "can follow import-macros")
;; (it "can go to the definition even in a lua file") ;; (it "can go to the definition even in a lua file")
;; (it "can go to a function's arguments when they're available")