Rename language -> analyzer
This commit is contained in:
parent
c56ce89ccf
commit
8dc4f3d0f8
44
rockspecs/fennel-ls-scm-3.rockspec
Normal file
44
rockspecs/fennel-ls-scm-3.rockspec
Normal file
@ -0,0 +1,44 @@
|
||||
package = "fennel-ls"
|
||||
version = "scm-3"
|
||||
source = {
|
||||
url = "git+https://git.sr.ht/~xerool/fennel-ls"
|
||||
}
|
||||
description = {
|
||||
summary = "A language server that analyzes Fennel, a lisp that compiles to Lua",
|
||||
detailed = "LSP magic for Fennel",
|
||||
homepage = "https://sr.ht/~xerool/fennel-ls",
|
||||
license = "MIT",
|
||||
}
|
||||
dependencies = {
|
||||
"lua >= 5.1",
|
||||
"luarocks-build-fennel >= 0.1",
|
||||
"fennel >= 1.4.1",
|
||||
}
|
||||
build = {
|
||||
type = "fennel",
|
||||
|
||||
modules = {
|
||||
["fennel-ls"] = "src/fennel-ls.fnl",
|
||||
["fennel-ls.compiler"] = "src/fennel-ls/compiler.fnl",
|
||||
["fennel-ls.config"] = "src/fennel-ls/config.fnl",
|
||||
["fennel-ls.dispatch"] = "src/fennel-ls/dispatch.fnl",
|
||||
["fennel-ls.docs"] = "src/fennel-ls/docs.fnl",
|
||||
["fennel-ls.docs.lua51"] = "src/fennel-ls/docs/lua51.fnl",
|
||||
["fennel-ls.docs.lua52"] = "src/fennel-ls/docs/lua52.fnl",
|
||||
["fennel-ls.docs.lua53"] = "src/fennel-ls/docs/lua53.fnl",
|
||||
["fennel-ls.docs.lua54"] = "src/fennel-ls/docs/lua54.fnl",
|
||||
["fennel-ls.docs.tic80"] = "src/fennel-ls/docs/tic80.fnl",
|
||||
["fennel-ls.files"] = "src/fennel-ls/files.fnl",
|
||||
["fennel-ls.formatter"] = "src/fennel-ls/formatter.fnl",
|
||||
["fennel-ls.handlers"] = "src/fennel-ls/handlers.fnl",
|
||||
["fennel-ls.json-rpc"] = "src/fennel-ls/json-rpc.fnl",
|
||||
["fennel-ls.json.json"] = "src/fennel-ls/json/json.lua",
|
||||
["fennel-ls.analyzer"] = "src/fennel-ls/analyzer.fnl",
|
||||
["fennel-ls.lint"] = "src/fennel-ls/lint.fnl",
|
||||
["fennel-ls.message"] = "src/fennel-ls/message.fnl",
|
||||
["fennel-ls.searcher"] = "src/fennel-ls/searcher.fnl",
|
||||
["fennel-ls.utils"] = "src/fennel-ls/utils.fnl",
|
||||
},
|
||||
|
||||
install = { bin = {["fennel-ls"] = "src/fennel-ls.fnl"} },
|
||||
}
|
||||
@ -9,7 +9,7 @@ Every time the client sends a message, it gets handled by a function in the corr
|
||||
(local message (require :fennel-ls.message))
|
||||
(local files (require :fennel-ls.files))
|
||||
(local config (require :fennel-ls.config))
|
||||
(local language (require :fennel-ls.language))
|
||||
(local analyzer (require :fennel-ls.analyzer))
|
||||
(local formatter (require :fennel-ls.formatter))
|
||||
(local utils (require :fennel-ls.utils))
|
||||
(local docs (require :fennel-ls.docs))
|
||||
@ -72,14 +72,14 @@ Every time the client sends a message, it gets handled by a function in the corr
|
||||
(λ requests.textDocument/definition [server send {: position :textDocument {: uri}}]
|
||||
(let [file (files.get-by-uri server uri)
|
||||
byte (utils.position->byte file.text position server.position-encoding)]
|
||||
(case-try (language.find-symbol file.ast byte)
|
||||
(case-try (analyzer.find-symbol file.ast byte)
|
||||
(symbol [parent])
|
||||
(if
|
||||
;; require call
|
||||
(. file.require-calls parent)
|
||||
(language.search-ast server file parent [] {:stop-early? true})
|
||||
(analyzer.search-ast server file parent [] {:stop-early? true})
|
||||
;; regular symbol
|
||||
(language.search-main server file symbol {:stop-early? true} {: byte}))
|
||||
(analyzer.search-main server file symbol {:stop-early? true} {: byte}))
|
||||
result
|
||||
(if result.file
|
||||
(message.range-and-uri server result.file (or result.binding result.definition)))
|
||||
@ -90,9 +90,9 @@ Every time the client sends a message, it gets handled by a function in the corr
|
||||
:context {:includeDeclaration ?include-declaration?}}]
|
||||
(let [file (files.get-by-uri server uri)
|
||||
byte (utils.position->byte file.text position server.position-encoding)]
|
||||
(case-try (language.find-symbol file.ast byte)
|
||||
(case-try (analyzer.find-symbol file.ast byte)
|
||||
symbol
|
||||
(language.find-nearest-definition server file symbol byte)
|
||||
(analyzer.find-nearest-definition server file symbol byte)
|
||||
(where definition (not= definition.referenced-by nil))
|
||||
(let [result (icollect [_ {: symbol} (ipairs definition.referenced-by)]
|
||||
(message.range-and-uri server definition.file symbol))]
|
||||
@ -107,14 +107,14 @@ Every time the client sends a message, it gets handled by a function in the corr
|
||||
(λ requests.textDocument/hover [server send {: position :textDocument {: uri}}]
|
||||
(let [file (files.get-by-uri server uri)
|
||||
byte (utils.position->byte file.text position server.position-encoding)]
|
||||
(case-try (language.find-symbol file.ast byte)
|
||||
symbol (language.search-main server file symbol {} {: byte})
|
||||
(case-try (analyzer.find-symbol file.ast byte)
|
||||
symbol (analyzer.search-main server file symbol {} {: byte})
|
||||
result {:contents (formatter.hover-format result)
|
||||
:range (message.ast->range server file symbol)}
|
||||
(catch _ nil))))
|
||||
|
||||
;; All of the helper functions for textDocument/completion are here until I
|
||||
;; finish refactoring them, and then they can find a home in language.fnl
|
||||
;; finish refactoring them, and then they can find a home in analyzer.fnl
|
||||
(λ collect-scope [scope typ callback ?target]
|
||||
(let [result (or ?target [])]
|
||||
(var scope scope)
|
||||
@ -132,7 +132,7 @@ Every time the client sends a message, it gets handled by a function in the corr
|
||||
:Constant 21 :Struct 22 :Event 23 :Operator 24 :TypeParameter 25})
|
||||
|
||||
(λ make-completion-item [server file name scope]
|
||||
(case (language.search-name-and-scope server file name scope)
|
||||
(case (analyzer.search-name-and-scope server file name scope)
|
||||
def (formatter.completion-item-format name def)
|
||||
_ {:label name}))
|
||||
|
||||
@ -158,7 +158,7 @@ Every time the client sends a message, it gets handled by a function in the corr
|
||||
(let [stack (fcollect [i (- (length split) 1) 2 -1]
|
||||
(. split i))
|
||||
last-found-binding []
|
||||
result (language.search-main server file symbol {:save-last-binding last-found-binding} {: stack})]
|
||||
result (analyzer.search-main server file symbol {:save-last-binding last-found-binding} {: stack})]
|
||||
(case result
|
||||
{: definition : file}
|
||||
(case (values definition (type definition))
|
||||
@ -174,7 +174,7 @@ Every time the client sends a message, it gets handled by a function in the corr
|
||||
label))
|
||||
(icollect [_ label (pairs keys)]
|
||||
(if (= (type label) :string)
|
||||
(case (language.search-ast server file tbl [label] {})
|
||||
(case (analyzer.search-ast server file tbl [label] {})
|
||||
def (formatter.completion-item-format label def)
|
||||
_ {: label :kind kinds.Field})))))
|
||||
{: metadata : fields}
|
||||
@ -186,7 +186,7 @@ Every time the client sends a message, it gets handled by a function in the corr
|
||||
(λ requests.textDocument/completion [server send {: position :textDocument {: uri}}]
|
||||
(let [file (files.get-by-uri server uri)
|
||||
byte (utils.position->byte file.text position server.position-encoding)
|
||||
(?symbol parents) (language.find-symbol file.ast byte)]
|
||||
(?symbol parents) (analyzer.find-symbol file.ast byte)]
|
||||
(case (-?> ?symbol utils.multi-sym-split)
|
||||
|
||||
;; completion from current scope
|
||||
@ -218,9 +218,9 @@ Every time the client sends a message, it gets handled by a function in the corr
|
||||
(λ requests.textDocument/rename [server send {: position :textDocument {: uri} :newName new-name}]
|
||||
(let [file (files.get-by-uri server uri)
|
||||
byte (utils.position->byte file.text position server.position-encoding)]
|
||||
(case-try (language.find-symbol file.ast byte)
|
||||
(case-try (analyzer.find-symbol file.ast byte)
|
||||
symbol
|
||||
(language.find-nearest-definition server file symbol symbol.bytestart)
|
||||
(analyzer.find-nearest-definition server file symbol symbol.bytestart)
|
||||
;; TODO we are assuming that every reference is in the same file
|
||||
(where definition (not= definition.referenced-by nil))
|
||||
(let [usages (icollect [_ {: symbol} (ipairs definition.referenced-by)
|
||||
|
||||
@ -3,7 +3,7 @@ Provides the function (check server file), which goes through a file and mutates
|
||||
the `file.diagnostics` field, filling it with diagnostics."
|
||||
|
||||
(local {: sym? : list? : view} (require :fennel))
|
||||
(local language (require :fennel-ls.language))
|
||||
(local analyzer (require :fennel-ls.analyzer))
|
||||
(local message (require :fennel-ls.message))
|
||||
(local utils (require :fennel-ls.utils))
|
||||
(local {:scopes {:global {: specials}}}
|
||||
@ -46,7 +46,7 @@ the `file.diagnostics` field, filling it with diagnostics."
|
||||
(icollect [symbol (pairs file.references) &into file.diagnostics]
|
||||
(if (. (utils.multi-sym-split symbol) 2)
|
||||
(let [opts {}
|
||||
item (language.search-ast server file symbol [] opts)]
|
||||
item (analyzer.search-ast server file symbol [] opts)]
|
||||
(if (and (not item) opts.searched-through-require-with-stack-size-1)
|
||||
{:range (message.ast->range server file symbol)
|
||||
:message (.. "unknown field: " (tostring symbol))
|
||||
|
||||
@ -99,7 +99,7 @@
|
||||
[{:code 302 :message "unknown field: table.insert2"}]
|
||||
[{:code 302 :message "unknown field: table.insert"}])
|
||||
;; if you explicitly write "_G", it should turn off this test.
|
||||
;; Hardcoded at the top of language.fnl/search-document.
|
||||
;; Hardcoded at the top of analyzer.fnl/search-document.
|
||||
(check "_G.insert2"
|
||||
[]
|
||||
[{:code 302}])
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
(local fennel (require :fennel))
|
||||
(local {: create-client-with-files} (require :test.utils))
|
||||
|
||||
(local language (require :fennel-ls.language))
|
||||
(local analyzer (require :fennel-ls.analyzer))
|
||||
(local utils (require :fennel-ls.utils))
|
||||
|
||||
|
||||
@ -18,7 +18,7 @@
|
||||
(fn test-find-symbol []
|
||||
(let [{: server : uri} (create-client-with-files "(match [1 2 4] [1 2 sym-one] sym-one)")
|
||||
file (. server.files uri)
|
||||
(symbol parents) (language.find-symbol file.ast 23)]
|
||||
(symbol parents) (analyzer.find-symbol file.ast 23)]
|
||||
(faith.= symbol (fennel.sym :sym-one))
|
||||
(faith.=
|
||||
"[[1 2 sym-one] (match [1 2 4] [1 2 sym-one] sym-one) [(match [1 2 4] [1 2 sym-one] sym-one)]]"
|
||||
@ -27,7 +27,7 @@
|
||||
|
||||
(let [{: server : uri} (create-client-with-files "(match [1 2 4] [1 2 sym-one] sym-one)")
|
||||
file (. server.files uri)
|
||||
(symbol parents) (language.find-symbol file.ast 18)]
|
||||
(symbol parents) (analyzer.find-symbol file.ast 18)]
|
||||
(faith.= symbol nil)
|
||||
(faith.=
|
||||
"[[1 2 sym-one] (match [1 2 4] [1 2 sym-one] sym-one) [(match [1 2 4] [1 2 sym-one] sym-one)]]"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user