Closed cn-kali-team closed 2 years ago
That would require serializing to JSON and back internally.
I can probably just make a function that outputs FnMetadata
types directly so the JSON step is no longer necessary...
However, many developers will register different function and structure types in their own engines, which requires recompiling rhai-lsp
.
It is more convenient for individual developers to export JSON as an automatic completion extension
True. The LSP can take such JSON export and get list of all registered functions.
This sounds perfect, much better than my original idea of embedding the LSP.
As far as I see, it should be trivial to generate declaration files from the given metadata, which the LSP already understands.
I'm not yet familiar with the internals, how much effort would it be to include doc comments in this metadata as well?
Also initially I didn't want to touch the engine itself, but it will be inevitable if we want to get the best experience out of the LSP. Would it be possible (from time and maintainability standpoint) to extend the Rhai parser and macros to parse doc comments and other metadata in the future for the LSP, probably gated by a feature or debug builds so it doesn't interfere with performance?
I'm not yet familiar with the internals, how much effort would it be to include doc comments in this metadata as well?
It would require the metadata
feature which requires serde
. Doc comments, I think, is already included in the JSON.
Yes, we don't need to parse the document as the data source, because Metadata already has enough information to provide to the LSP.
Come to think of it... Rhai automatically extracts doc-comments that are put on top of plugin functions into the JSON metadata.
This means that it is possible for the LSP to pick up the comments and potentially display it to the user as popup info.
Right now there are no doc-comments for the Rhai standard library, but maybe I should start adding them!
Come to think of it... Rhai automatically extracts doc-comments that are put on top of plugin functions into the JSON metadata.
Great, that's very convenient then. To sum this up a bit, we might need or have:
Right now there are no doc-comments for the Rhai standard library, but maybe I should start adding them!
No need to hurry. I still have exams, and a project deadline on 24th, I can only continue work on the LSP after.
signature (parameter count but no type information I assume)
Script-defined function parameters are always Dynamic
, and returns Dynamic
, so the type is deterministic!
functions registered in Rust at runtime
You still get a signature with parameter types, but not the actual name of the parameters. So the signature will be something like fn foo(_: i64, _: bool) -> String
.
Dear all, if you'd pull from the latest dev repo, you'll find that gen_fn_metadata_to_json
includes doc-comments for all standard library functions including examples!
When do we expect the feature to load metadata files? With this, all the errors will go away and the LSP is actually usable!
BTW, there are a number of "standard" functions that should be automatically recognized because they are built-in. They are counted as reserved keywords:
print
debug
type_of
Fn
call
curry
is_def_fn
is_def_var
is_shared
eval
When do we expect the feature to load metadata files?
I'll work on this after I fixed the current bugs :)
there are a number of "standard" functions
Are these included in any of the generated metadata? If not, definition files will have to be hand-written.
Are these included in any of the generated metadata? If not, definition files will have to be hand-written.
Unfortunately no... But I can write them for you.
It is better to have free-form docs for these, as they can be special. For example, the call
and carry
functions take a variable number of parameters.
We can use
engine.gen_fn_metadata_to_json
, generate the function and data type structure, and importlsp
as the function and structure type registered by the extension developer.json::
,automatically completeload
ordump
.