allow docs to set the item kind

This commit is contained in:
Michele Campeotto 2025-02-24 09:28:36 +01:00 committed by Phil Hagelberg
parent bbc6ec4d62
commit 1d2ea48c16
5 changed files with 14 additions and 10 deletions

View File

@ -109,7 +109,7 @@ fntype is one of fn or λ or lambda"
{:fntype _} {: label {:fntype _} {: label
:kind (if (label:find ":") kinds.Method kinds.Function)} :kind (if (label:find ":") kinds.Method kinds.Function)}
_ {: label _ {: label
:kind kinds.Variable}) :kind (. kinds (?. result :metadata :fls/itemKind))})
(tset :documentation (hover-format result)))) (tset :documentation (hover-format result))))
{: hover-format {: hover-format

View File

@ -71,8 +71,7 @@
(expected completions)))) (expected completions))))
(fn test-global [] (fn test-global []
;; TODO shouldn't this kind be Function? (check "(" [{:label :setmetatable :kind kinds.Function}] [])
(check "(" [{:label :setmetatable :kind kinds.Variable}] [])
(check "(" [:_G :debug :table :io :getmetatable :setmetatable :_VERSION :ipairs :pairs :next] [:this-is-not-a-global]) (check "(" [:_G :debug :table :io :getmetatable :setmetatable :_VERSION :ipairs :pairs :next] [:this-is-not-a-global])
(check "#nil\n(" [:_G :debug :table :io :getmetatable :setmetatable :_VERSION :ipairs :pairs :next] []) (check "#nil\n(" [:_G :debug :table :io :getmetatable :setmetatable :_VERSION :ipairs :pairs :next] [])
(check "(if ge" [:getmetatable] []) (check "(if ge" [:getmetatable] [])

View File

@ -8,13 +8,14 @@
; ;
; UTILS ; UTILS
; ----- ; -----
(fn build-lsp-value [name ?args ?docstring ?fields] (fn build-lsp-value [name ?args ?docstring ?fields ?kind]
"Takes ... and returns a table to be used with the LSP." "Takes ... and returns a table to be used with the LSP."
(let [lsp-value {:binding name} (let [lsp-value {:binding name}
?metadata (or ?args ?docstring)] ?metadata (or ?args ?docstring)]
(when ?metadata (set lsp-value.metadata {})) (when ?metadata (set lsp-value.metadata {}))
(when ?args (set lsp-value.metadata.fnl/arglist ?args)) (when ?args (set lsp-value.metadata.fnl/arglist ?args))
(when ?docstring (set lsp-value.metadata.fnl/docstring ?docstring)) (when ?docstring (set lsp-value.metadata.fnl/docstring ?docstring))
(when ?kind (set lsp-value.metadata.fls/itemKind ?kind))
(when ?fields (set lsp-value.fields ?fields)) (when ?fields (set lsp-value.fields ?fields))
lsp-value)) lsp-value))
@ -69,7 +70,7 @@
?args (?. first-variant :args) ?args (?. first-variant :args)
?returns (or (?. first-variant :returns) "") ?returns (or (?. first-variant :returns) "")
docstring (.. description ?returns)] docstring (.. description ?returns)]
(values name (build-lsp-value binding ?args docstring))))) (values name (build-lsp-value binding ?args docstring nil :Function)))))
(fn module-list->lsp-table [modules ?namespace] (fn module-list->lsp-table [modules ?namespace]
(collect [_i module (ipairs modules)] (collect [_i module (ipairs modules)]
@ -84,7 +85,7 @@
{}) {})
module-keys (if ?modules (module-list->lsp-table ?modules binding) {}) module-keys (if ?modules (module-list->lsp-table ?modules binding) {})
fields (merge function-keys module-keys)] fields (merge function-keys module-keys)]
(values name (build-lsp-value binding nil ?docstring fields))))) (values name (build-lsp-value binding nil ?docstring fields :Module)))))
(fn love-api->lsp-table [love-api] (fn love-api->lsp-table [love-api]
(let [root-module {:description (.. "LÖVE is a framework for making 2D " (let [root-module {:description (.. "LÖVE is a framework for making 2D "

View File

@ -133,13 +133,15 @@
description (html-to-markdown description) description (html-to-markdown description)
name (signature:match "[^() ]+") name (signature:match "[^() ]+")
key (name:match "[^.:]+$") key (name:match "[^.:]+$")
?module (and (name:find "[.:]") (name:match "^[^.:]+"))] ?module (and (name:find "[.:]") (name:match "^[^.:]+"))
kind (if (signature:find "[()]") :Function :Variable)]
(values ?module (values ?module
key key
{:binding (signature:match "[^() ]+") {:binding (signature:match "[^() ]+")
:metadata {:fnl/docstring description :metadata {:fnl/docstring description
:fnl/arglist signature-list}}))) :fnl/arglist signature-list
:fls/itemKind kind}})))
(fn parse-h2-section [html] (fn parse-h2-section [html]
"parse a section that starts with an h2 tag. These are the main modules." "parse a section that starts with an h2 tag. These are the main modules."
@ -169,7 +171,8 @@
(values module-name (values module-name
{:binding module-name {:binding module-name
:fields {} :fields {}
:metadata {:fnl/docstring description}}))) :metadata {:fnl/docstring description
:fls/itemKind :Module}})))
(fn parse [input] (fn parse [input]
(let [version (input:match "Lua .- Reference Manual") (let [version (input:match "Lua .- Reference Manual")

View File

@ -25,7 +25,8 @@
"([_%w]+)%s+`([^`]+)`%s(.-)\n### ")] "([_%w]+)%s+`([^`]+)`%s(.-)\n### ")]
(let [arglist (markdown->arglist args)] (let [arglist (markdown->arglist args)]
(values name {:metadata {:fnl/arglist arglist (values name {:metadata {:fnl/arglist arglist
:fnl/docstring docs} :fnl/docstring docs
:fls/itemKind :Function}
:binding name}))))) :binding name})))))
(fn convert [contents] (fn convert [contents]