Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion internal/fourslash/_scripts/failingTests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,6 @@ TestQuickInfoOnInternalAliases
TestQuickInfoOnJsxNamespacedNameWithDoc1
TestQuickInfoOnMergedModule
TestQuickInfoOnNarrowedTypeInModule
TestQuickInfoOnNewKeyword01
TestQuickInfoOnObjectLiteralWithAccessors
TestQuickInfoOnObjectLiteralWithOnlyGetter
TestQuickInfoOnObjectLiteralWithOnlySetter
Expand Down
56 changes: 56 additions & 0 deletions internal/fourslash/tests/completionsInJsxTag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,59 @@ class Foo {
},
})
}

func TestCompletionsInJsxNamespacedIntrinsicTag(t *testing.T) {
t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `// @jsx: react
// @Filename: /a.tsx
declare const React: any;
declare namespace JSX {
interface Element {}
interface IntrinsicElements {
/** Element docs */
"foo:bar": {
/** Foo docs */
foo: boolean
/** Bar docs */
bar: string
}
}
}
<foo:bar /*1*/ />
<foo:bar /*2*/></foo:bar>`
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
defer done()
f.VerifyCompletions(t, []string{"1", "2"}, &fourslash.CompletionsExpectedList{
IsIncomplete: false,
ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{
CommitCharacters: &DefaultCommitCharacters,
},
Items: &fourslash.CompletionsExpectedItems{
Exact: []fourslash.CompletionsExpectedItem{
&lsproto.CompletionItem{
Label: "bar",
Kind: new(lsproto.CompletionItemKindField),
Detail: new("(property) bar: string"),
Documentation: &lsproto.StringOrMarkupContent{
MarkupContent: &lsproto.MarkupContent{
Kind: lsproto.MarkupKindMarkdown,
Value: "Bar docs",
},
},
},
&lsproto.CompletionItem{
Label: "foo",
Kind: new(lsproto.CompletionItemKindField),
Detail: new("(property) foo: boolean"),
Documentation: &lsproto.StringOrMarkupContent{
MarkupContent: &lsproto.MarkupContent{
Kind: lsproto.MarkupKindMarkdown,
Value: "Foo docs",
},
},
},
},
},
})
}
33 changes: 33 additions & 0 deletions internal/fourslash/tests/quickInfoJsxNamespacedIntrinsic_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package fourslash_test

import (
"testing"

"github.com/microsoft/typescript-go/internal/fourslash"
"github.com/microsoft/typescript-go/internal/testutil"
)

func TestQuickInfoJsxNamespacedIntrinsic(t *testing.T) {
t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `// @jsx: react
// @Filename: /a.tsx
declare const React: any;
declare namespace JSX {
interface Element {}
interface IntrinsicElements {
/** Element docs */
"foo:bar": {
/** Foo docs */
foo: boolean
/** Bar docs */
bar: string
}
}
}
<foo:ba/*tag*/r fo/*attr*/o />`
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
defer done()
f.VerifyQuickInfoAt(t, "tag", "(property) JSX.IntrinsicElements[\"foo:bar\"]: {\n foo: boolean;\n bar: string;\n}", "Element docs")
f.VerifyQuickInfoAt(t, "attr", "(property) foo: boolean", "Foo docs")
}
5 changes: 4 additions & 1 deletion internal/ls/completions.go
Original file line number Diff line number Diff line change
Expand Up @@ -4153,7 +4153,7 @@ func tryGetContainingJsxElement(contextToken *ast.Node, file *ast.SourceFile) *a
parent := contextToken.Parent
switch contextToken.Kind {
case ast.KindGreaterThanToken, ast.KindLessThanSlashToken, ast.KindSlashToken, ast.KindIdentifier,
ast.KindPropertyAccessExpression, ast.KindJsxAttributes, ast.KindJsxAttribute, ast.KindJsxSpreadAttribute:
ast.KindPropertyAccessExpression, ast.KindJsxNamespacedName, ast.KindJsxAttributes, ast.KindJsxAttribute, ast.KindJsxSpreadAttribute:
if parent != nil && (parent.Kind == ast.KindJsxSelfClosingElement || parent.Kind == ast.KindJsxOpeningElement) {
if contextToken.Kind == ast.KindGreaterThanToken {
precedingToken := astnav.FindPrecedingToken(file, contextToken.Pos())
Expand All @@ -4163,6 +4163,9 @@ func tryGetContainingJsxElement(contextToken *ast.Node, file *ast.SourceFile) *a
}
}
return parent
} else if parent != nil && ast.IsJsxNamespacedName(parent) &&
parent.Parent != nil && (parent.Parent.Kind == ast.KindJsxSelfClosingElement || parent.Parent.Kind == ast.KindJsxOpeningElement) {
return parent.Parent
} else if parent != nil && parent.Kind == ast.KindJsxAttribute {
// Currently we parse JsxOpeningLikeElement as:
// JsxOpeningLikeElement
Expand Down
2 changes: 1 addition & 1 deletion internal/ls/hover.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (l *LanguageService) ProvideHover(ctx context.Context, params *lsproto.Hove
c, done := program.GetTypeCheckerForFile(ctx, file)
defer done()
rangeNode := getNodeForQuickInfo(node)
symbol := getSymbolAtLocationForQuickInfo(c, node)
symbol := getSymbolAtLocationForQuickInfo(c, rangeNode)

// Always create VerbosityContext for hover so that canExpandSymbol can signal
// canIncreaseVerbosity even at Level 0. The nodebuilder also detects expandable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
// ^^^^^^^^^^^
// | ----------------------------------------------------------------------
// | ```typescript
// | (property) ImportMetaExpression.meta: ImportMeta
// | interface ImportMeta
// | ```
// | The type of `import.meta`.
// |
// | If you need to declare that a given property exists on `import.meta`,
// | this type may be augmented via interface merging.
// | ----------------------------------------------------------------------
[
{
Expand Down Expand Up @@ -39,7 +42,7 @@
"item": {
"contents": {
"kind": "markdown",
"value": "```typescript\n(property) ImportMetaExpression.meta: ImportMeta\n```\n"
"value": "```typescript\ninterface ImportMeta\n```\nThe type of `import.meta`.\n\nIf you need to declare that a given property exists on `import.meta`,\nthis type may be augmented via interface merging."
},
"range": {
"start": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
// === QuickInfo ===
=== /a.tsx ===
// <a:b a="accepted" b="rejected" />;
// ^
// ^^^
// | ----------------------------------------------------------------------
// | No quickinfo at /**/.
// | ```typescript
// | (property) JSX.IntrinsicElements['a:b']: {
// | a: string;
// | }
// | ```
// |
// | ----------------------------------------------------------------------
[
{
Expand All @@ -16,6 +21,21 @@
"Name": "",
"Data": {}
},
"item": null
"item": {
"contents": {
"kind": "markdown",
"value": "```typescript\n(property) JSX.IntrinsicElements['a:b']: {\n a: string;\n}\n```\n"
},
"range": {
"start": {
"line": 0,
"character": 1
},
"end": {
"line": 0,
"character": 4
}
}
}
}
]