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
:kind (if (label:find ":") kinds.Method kinds.Function)}
_ {: label
:kind kinds.Variable})
:kind (. kinds (?. result :metadata :fls/itemKind))})
(tset :documentation (hover-format result))))
{: hover-format

View File

@ -71,8 +71,7 @@
(expected completions))))
(fn test-global []
;; TODO shouldn't this kind be Function?
(check "(" [{:label :setmetatable :kind kinds.Variable}] [])
(check "(" [{:label :setmetatable :kind kinds.Function}] [])
(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 "(if ge" [:getmetatable] [])

View File

@ -8,13 +8,14 @@
;
; 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."
(let [lsp-value {:binding name}
?metadata (or ?args ?docstring)]
(when ?metadata (set lsp-value.metadata {}))
(when ?args (set lsp-value.metadata.fnl/arglist ?args))
(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))
lsp-value))
@ -69,7 +70,7 @@
?args (?. first-variant :args)
?returns (or (?. first-variant :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]
(collect [_i module (ipairs modules)]
@ -84,7 +85,7 @@
{})
module-keys (if ?modules (module-list->lsp-table ?modules binding) {})
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]
(let [root-module {:description (.. "LÖVE is a framework for making 2D "

View File

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

View File

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