Renaming search to search-ast

I think this is a slightly better name, but I'm still not sure what to
call this function.
This commit is contained in:
XeroOl 2024-01-24 16:45:39 -06:00
parent b2ec7e5a3a
commit 6e68552940
3 changed files with 18 additions and 16 deletions

View File

@ -23,7 +23,7 @@ Goes through a file and mutates the `file.diagnostics` field, filling it with di
(icollect [symbol (pairs file.references) &into file.diagnostics]
(if (. (utils.multi-sym-split symbol) 2)
(let [opts {}
item (language.search self file symbol [] opts)]
item (language.search-ast self file symbol [] opts)]
(if (and (not item) opts.searched-through-require)
{:range (message.ast->range self file symbol)
:message (.. "unknown field: " (tostring symbol))

View File

@ -74,7 +74,7 @@ Every time the client sends a message, it gets handled by a function in the corr
(if
;; require call
(. file.require-calls parent)
(language.search self file parent [] {:stop-early? true})
(language.search-ast self file parent [] {:stop-early? true})
;; regular symbol
(language.search-main self file symbol {:stop-early? true} byte))
(result result-file)
@ -157,11 +157,13 @@ Every time the client sends a message, it gets handled by a function in the corr
(case (language.search-assignment self file ref stack {})
({: definition} file)
(case (values definition (type definition))
;; fields of a string are hardcoded to "string"
(_str :string) (icollect [label _ (pairs string)]
{: label :kind kinds.Field})
;; fields of a table
(tbl :table) (icollect [label _ (pairs tbl)]
(if (= (type label) :string)
(case (language.search self file tbl [label] {})
(case (language.search-ast self file tbl [label] {})
def (formatter.completion-item-format label def)
_ {: label :kind kinds.Field}))))
_ nil))))

View File

@ -16,7 +16,7 @@ the data provided by compiler.fnl."
(local -nil- (sym :nil))
(local -setmetatable- (sym :setmetatable))
(var search nil) ;; all of the search functions are mutually recursive
(var search-ast nil) ;; all of the search functions are mutually recursive
(λ stack-add-keys! [stack ?keys]
"add the keys to the end of the stack in reverse order"
@ -44,7 +44,7 @@ the data provided by compiler.fnl."
;; search a virtual field from :fields
(and (not= 0 (length stack)) (?. ?fields (. stack (length stack))))
(search-assignment self file (. ?fields (table.remove stack)) stack opts)
(search self file ?definition (stack-add-keys! stack ?keys) opts))))
(search-ast self file ?definition (stack-add-keys! stack ?keys) opts))))
(λ search-symbol [self file symbol stack opts]
(if (= symbol -nil-)
@ -54,7 +54,7 @@ the data provided by compiler.fnl."
(λ search-table [self file tbl stack opts]
(if (. tbl (. stack (length stack)))
(search self file (. tbl (table.remove stack)) stack opts)
(search-ast self file (. tbl (table.remove stack)) stack opts)
(= 0 (length stack))
(values {:definition tbl} file) ;; BASE CASE !!
nil)) ;; BASE CASE Give up
@ -66,22 +66,22 @@ the data provided by compiler.fnl."
(let [newfile (state.get-by-module self mod)]
(when newfile
(let [newitem (. newfile.ast (length newfile.ast))]
(search self newfile newitem stack (doto opts (tset :searched-through-require true)))))))
(search-ast self newfile newitem stack (doto opts (tset :searched-through-require true)))))))
;; A . form indexes into item 1 with the other items
(where [-dot- & split] (. split 1))
(search self file (. split 1) (stack-add-split! stack split) opts)
(search-ast self file (. split 1) (stack-add-split! stack split) opts)
;; A do block returns the last form
(where [-do- & body] (. body 1))
(search self file (. body (length body)) stack opts)
(search-ast self file (. body (length body)) stack opts)
(where [-let- _binding & body] (. body 1))
(search self file (. body (length body)) stack opts)
(search-ast self file (. body (length body)) stack opts)
;; TODO care about the setmetatable call
(where [-setmetatable- tbl _mt])
(search self file tbl stack opts)
(search-ast self file tbl stack opts)
;; functions evaluate to "themselves"
[-fn-]
@ -92,8 +92,8 @@ the data provided by compiler.fnl."
(if (= 0 (length stack))
(values {:definition call} file)))) ;; BASE CASE!!
(set search
search [self file item stack opts]
(set search-ast
(λ [self file item stack opts]
(if
(sym? item) (search-symbol self file item stack opts)
(list? item) (search-list self file item stack opts)
@ -146,7 +146,7 @@ Returns:
_ (case (. file.references symbol)
ref (search-assignment self file ref stack opts)
_ (case (. file.definitions symbol)
def (search self file def.definition (stack-add-keys! stack def.keys) opts)))))))
def (search-ast self file def.definition (stack-add-keys! stack def.keys) opts)))))))
(λ find-local-definition [file name ?scope]
(when ?scope
@ -167,7 +167,7 @@ Returns:
_ (case (global-info self name)
global-item global-item
_ (case (find-local-definition file name scope)
def (search self file def.definition (stack-add-keys! stack def.keys) (or ?opts {})))))))
def (search-ast self file def.definition (stack-add-keys! stack def.keys) (or ?opts {})))))))
(λ _past? [?ast byte]
;; check if a byte is past an ast object
@ -235,4 +235,4 @@ Returns:
: search-main
: search-assignment
: search-name-and-scope
: search}
: search-ast}