Skip to content

Commit 9eece40

Browse files
committed
Parse documentation in doc file classes
1 parent ecd199c commit 9eece40

File tree

2 files changed

+40
-8
lines changed

2 files changed

+40
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1616
- Added configuration `luau-lsp.bytecode.vectorLib`, `luau-lsp.bytecode.vectorCtor` and `luau-lsp.bytecode.vectorType` to configure compiler options when generating bytecode
1717
- Custom editors should handle the `luau-lsp/bytecode` and `luau-lsp/compilerRemarks` LSP message to integrate compiler remarks info in their editor
1818
- Added `luau-lsp.types.robloxSecurityLevel` to select what security level to use for the API types, out of: `None`, `LocalUserSecurity`, `PluginSecurity` and `RobloxScriptSecurity`
19+
- Added support for documentation in definitions files
1920

2021
### Changed
2122

src/DocumentationParser.cpp

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,26 @@ struct AttachCommentsVisitor : public Luau::AstVisitor
330330
return false;
331331
}
332332

333+
bool visit(Luau::AstStatDeclareClass* klass) override
334+
{
335+
if (klass->location.begin >= pos)
336+
return false;
337+
if (klass->location.begin > closestPreviousNode)
338+
closestPreviousNode = klass->location.begin;
339+
340+
for (const auto& item : klass->props)
341+
{
342+
if (item.ty->location.begin >= pos)
343+
continue;
344+
closestPreviousNode = std::max(closestPreviousNode, item.ty->location.begin);
345+
item.ty->visit(this);
346+
if (item.ty->location.end <= pos)
347+
closestPreviousNode = std::max(closestPreviousNode, item.ty->location.end);
348+
}
349+
350+
return false;
351+
}
352+
333353
bool visit(Luau::AstStatBlock* block) override
334354
{
335355
// If the position is after the block, then it can be ignored
@@ -372,19 +392,30 @@ std::vector<Luau::Comment> getCommentLocations(const Luau::SourceModule* module,
372392
/// Performs transformations so that the comments are normalised to lines inside of it (i.e., trimming whitespace, removing comment start/end)
373393
std::vector<std::string> WorkspaceFolder::getComments(const Luau::ModuleName& moduleName, const Luau::Location& node)
374394
{
375-
auto sourceModule = frontend.getSourceModule(moduleName);
376-
if (!sourceModule)
377-
return {};
395+
Luau::SourceModule* sourceModule;
396+
TextDocumentPtr textDocument(nullptr);
397+
398+
if (auto sm = definitionsSourceModules.find(moduleName); sm != definitionsSourceModules.end())
399+
{
400+
sourceModule = &sm->second.second;
401+
textDocument = TextDocumentPtr(&sm->second.first);
402+
}
403+
else
404+
{
405+
sourceModule = frontend.getSourceModule(moduleName);
406+
if (!sourceModule)
407+
return {};
408+
409+
// Get relevant text document
410+
textDocument = fileResolver.getOrCreateTextDocumentFromModuleName(moduleName);
411+
if (!textDocument)
412+
return {};
413+
}
378414

379415
auto commentLocations = getCommentLocations(sourceModule, node);
380416
if (commentLocations.empty())
381417
return {};
382418

383-
// Get relevant text document
384-
auto textDocument = fileResolver.getOrCreateTextDocumentFromModuleName(moduleName);
385-
if (!textDocument)
386-
return {};
387-
388419
std::vector<std::string> comments{};
389420
for (auto& comment : commentLocations)
390421
{

0 commit comments

Comments
 (0)