Skip to content

Commit

Permalink
[tests] Add test for #5709 (#11934)
Browse files Browse the repository at this point in the history
* [tests] Add test for #5709

* [tests] Json RPC tests vs hover requests for type documentation

* [tests] Better typing for extractDoc
  • Loading branch information
kLabz authored Jan 22, 2025
1 parent 4a05a73 commit 11dd355
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 10 deletions.
26 changes: 16 additions & 10 deletions tests/display/src/RpcDisplayTestContext.hx
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,7 @@ class RpcDisplayTestContext extends BaseDisplayTestContext {
}

public function metadataDoc(pos:Position):String {
return extractMetadata(callDisplay(DisplayMethods.Hover, {
file: new FsPath(source.path),
offset: pos,
}).result);
return doc(pos);
}

public function diagnostics():Array<Diagnostic<Any>> {
Expand Down Expand Up @@ -155,11 +152,20 @@ class RpcDisplayTestContext extends BaseDisplayTestContext {
return '$path:${start.line + 1}: $pos';
}

function extractDoc(result:HoverDisplayItemOccurence<Dynamic>) {
return StringTools.trim(result.item.args.field.doc);
}

function extractMetadata(result:HoverDisplayItemOccurence<Dynamic>) {
return result.item.args.doc;
function extractDoc<T>(result:HoverDisplayItemOccurence<T>) {
return switch result.item.kind {
case ClassField | EnumAbstractField:
StringTools.trim(result.item.args.field.doc);
case EnumField:
StringTools.trim(result.item.args.field.doc);
case Type:
StringTools.trim(result.item.args.doc);
case Metadata:
result.item.args.doc;
case Define:
result.item.args.doc;
case _:
null;
};
}
}
28 changes: 28 additions & 0 deletions tests/display/src/cases/Issue5709.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package cases;

class Issue5709 extends DisplayTestCase {
/**
class Main {
public static function main() {
var foo:F{-1-}oo = new F{-2-}oo();
}
}
/** Foo doc **\/
class Foo {
public function new() {}
}
/** IBaz doc **\/
interface IBaz {}
class Bar extends F{-3-}oo {}
class Baz implements I{-5-}Baz {}
typedef Foos = Array<F{-4-}oo>;
**/
function test() {
for (i in 1...5) eq("Foo doc", doc(pos(i)));
eq("IBaz doc", doc(pos(5)));
}
}

0 comments on commit 11dd355

Please sign in to comment.