diff --git a/src/services/symbolDisplay.ts b/src/services/symbolDisplay.ts index f9db3831f3b..6a5ab9a8b0d 100644 --- a/src/services/symbolDisplay.ts +++ b/src/services/symbolDisplay.ts @@ -60,7 +60,9 @@ import { isThisInTypeQuery, isTransientSymbol, isTypeAliasDeclaration, + isVarAwaitUsing, isVarConst, + isVarUsing, JSDocTagInfo, JsxOpeningLikeElement, keywordPart, @@ -161,6 +163,12 @@ function getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(typeCheck else if (symbol.valueDeclaration && isVarConst(symbol.valueDeclaration as VariableDeclaration)) { return ScriptElementKind.constElement; } + else if (symbol.valueDeclaration && isVarUsing(symbol.valueDeclaration as VariableDeclaration)) { + return ScriptElementKind.variableUsingElement; + } + else if (symbol.valueDeclaration && isVarAwaitUsing(symbol.valueDeclaration as VariableDeclaration)) { + return ScriptElementKind.variableAwaitUsingElement; + } else if (forEach(symbol.declarations, isLet)) { return ScriptElementKind.letElement; } @@ -630,6 +638,8 @@ export function getSymbolDisplayPartsDocumentationAndSymbolKind(typeChecker: Typ symbolFlags & SymbolFlags.Variable || symbolKind === ScriptElementKind.localVariableElement || symbolKind === ScriptElementKind.indexSignatureElement || + symbolKind === ScriptElementKind.variableUsingElement || + symbolKind === ScriptElementKind.variableAwaitUsingElement || isThisExpression) { displayParts.push(punctuationPart(SyntaxKind.ColonToken)); displayParts.push(spacePart()); @@ -807,6 +817,8 @@ export function getSymbolDisplayPartsDocumentationAndSymbolKind(typeChecker: Typ case ScriptElementKind.letElement: case ScriptElementKind.constElement: case ScriptElementKind.constructorImplementationElement: + case ScriptElementKind.variableUsingElement: + case ScriptElementKind.variableAwaitUsingElement: displayParts.push(textOrKeywordPart(symbolKind)); return; default: diff --git a/src/services/types.ts b/src/services/types.ts index ace7789a0ef..fad76f01c7b 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -1596,6 +1596,12 @@ export const enum ScriptElementKind { /** Inside function */ localVariableElement = "local var", + /** using foo = ... */ + variableUsingElement = "using", + + /** await using foo = ... */ + variableAwaitUsingElement = "await using", + /** * Inside module and script only * function f() { } diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 606d1a31964..825b4604e4c 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -10978,6 +10978,10 @@ declare namespace ts { variableElement = "var", /** Inside function */ localVariableElement = "local var", + /** using foo = ... */ + variableUsingElement = "using", + /** await using foo = ... */ + variableAwaitUsingElement = "await using", /** * Inside module and script only * function f() { } diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index a00cc6edf77..b96cd0e1b52 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -7009,6 +7009,10 @@ declare namespace ts { variableElement = "var", /** Inside function */ localVariableElement = "local var", + /** using foo = ... */ + variableUsingElement = "using", + /** await using foo = ... */ + variableAwaitUsingElement = "await using", /** * Inside module and script only * function f() { } diff --git a/tests/baselines/reference/quickInfoDisplayPartsUsing.baseline b/tests/baselines/reference/quickInfoDisplayPartsUsing.baseline new file mode 100644 index 00000000000..f71da8902a3 --- /dev/null +++ b/tests/baselines/reference/quickInfoDisplayPartsUsing.baseline @@ -0,0 +1,174 @@ +=== /tests/cases/fourslash/quickInfoDisplayPartsUsing.ts === +// using a = "a"; +// ^ +// | ---------------------------------------------------------------------- +// | using a: "a" +// | ---------------------------------------------------------------------- +// const f = async () => { +// await using b = { async [Symbol.asyncDispose]() {} }; +// ^ +// | ---------------------------------------------------------------------- +// | await using b: { +// | [Symbol.asyncDispose](): Promise; +// | } +// | ---------------------------------------------------------------------- +// }; + +[ + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsUsing.ts", + "position": 7, + "name": "a" + }, + "item": { + "kind": "using", + "kindModifiers": "", + "textSpan": { + "start": 6, + "length": 1 + }, + "displayParts": [ + { + "text": "using", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "a", + "kind": "localName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"a\"", + "kind": "stringLiteral" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsUsing.ts", + "position": 55, + "name": "b" + }, + "item": { + "kind": "await using", + "kindModifiers": "", + "textSpan": { + "start": 55, + "length": 1 + }, + "displayParts": [ + { + "text": "await using", + "kind": "text" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "b", + "kind": "localName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "{", + "kind": "punctuation" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "[", + "kind": "punctuation" + }, + { + "text": "Symbol", + "kind": "localName" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "asyncDispose", + "kind": "propertyName" + }, + { + "text": "]", + "kind": "punctuation" + }, + { + "text": "(", + "kind": "punctuation" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "Promise", + "kind": "localName" + }, + { + "text": "<", + "kind": "punctuation" + }, + { + "text": "void", + "kind": "keyword" + }, + { + "text": ">", + "kind": "punctuation" + }, + { + "text": ";", + "kind": "punctuation" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": "}", + "kind": "punctuation" + } + ], + "documentation": [] + } + } +] \ No newline at end of file diff --git a/tests/cases/fourslash/quickInfoDisplayPartsUsing.ts b/tests/cases/fourslash/quickInfoDisplayPartsUsing.ts new file mode 100644 index 00000000000..576ae73f0ca --- /dev/null +++ b/tests/cases/fourslash/quickInfoDisplayPartsUsing.ts @@ -0,0 +1,9 @@ +/// +// @lib: esnext + +////using a/*a*/ = "a"; +////const f = async () => { +//// await using /*b*/b = { async [Symbol.asyncDispose]() {} }; +////}; + +verify.baselineQuickInfo();