From 8dc4f3d0f8dcbfae8342e677d564e9b184e27a00 Mon Sep 17 00:00:00 2001 From: XeroOl Date: Wed, 5 Jun 2024 01:20:18 -0500 Subject: [PATCH] Rename language -> analyzer --- rockspecs/fennel-ls-scm-3.rockspec | 44 ++++++++++++++++++++ src/fennel-ls/{language.fnl => analyzer.fnl} | 0 src/fennel-ls/handlers.fnl | 30 ++++++------- src/fennel-ls/lint.fnl | 4 +- test/lint.fnl | 2 +- test/misc.fnl | 6 +-- 6 files changed, 65 insertions(+), 21 deletions(-) create mode 100644 rockspecs/fennel-ls-scm-3.rockspec rename src/fennel-ls/{language.fnl => analyzer.fnl} (100%) diff --git a/rockspecs/fennel-ls-scm-3.rockspec b/rockspecs/fennel-ls-scm-3.rockspec new file mode 100644 index 0000000..abd7a0c --- /dev/null +++ b/rockspecs/fennel-ls-scm-3.rockspec @@ -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"} }, +} diff --git a/src/fennel-ls/language.fnl b/src/fennel-ls/analyzer.fnl similarity index 100% rename from src/fennel-ls/language.fnl rename to src/fennel-ls/analyzer.fnl diff --git a/src/fennel-ls/handlers.fnl b/src/fennel-ls/handlers.fnl index 03c7177..e1eaa20 100644 --- a/src/fennel-ls/handlers.fnl +++ b/src/fennel-ls/handlers.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) diff --git a/src/fennel-ls/lint.fnl b/src/fennel-ls/lint.fnl index 7745f18..9d8b24c 100644 --- a/src/fennel-ls/lint.fnl +++ b/src/fennel-ls/lint.fnl @@ -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)) diff --git a/test/lint.fnl b/test/lint.fnl index a99d618..9bd7621 100644 --- a/test/lint.fnl +++ b/test/lint.fnl @@ -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}]) diff --git a/test/misc.fnl b/test/misc.fnl index 4660083..cf7dce9 100644 --- a/test/misc.fnl +++ b/test/misc.fnl @@ -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)]]"