Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6f9dc2f

Browse files
authored
Merge pull requestmicrosoft#23923 from Zzzen/master
Document highlights on async/await keywords should highlight other oc…
2 parents9ea4d93 +91a15dc commit6f9dc2f

File tree

4 files changed

+87
-0
lines changed

4 files changed

+87
-0
lines changed

‎src/services/documentHighlights.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ namespace ts.DocumentHighlights {
7474
caseSyntaxKind.GetKeyword:
7575
caseSyntaxKind.SetKeyword:
7676
returngetFromAllDeclarations(isAccessor,[SyntaxKind.GetKeyword,SyntaxKind.SetKeyword]);
77+
caseSyntaxKind.AwaitKeyword:
78+
returnuseParent(node.parent,isAwaitExpression,getAsyncAndAwaitOccurrences);
79+
caseSyntaxKind.AsyncKeyword:
80+
returnhighlightSpans(getAsyncAndAwaitOccurrences(node));
7781
default:
7882
returnisModifierKind(node.kind)&&(isDeclaration(node.parent)||isVariableStatement(node.parent))
7983
?highlightSpans(getModifierOccurrences(node.kind,node.parent))
@@ -368,6 +372,35 @@ namespace ts.DocumentHighlights {
368372
returnkeywords;
369373
}
370374

375+
functiongetAsyncAndAwaitOccurrences(node:Node):Node[]|undefined{
376+
constfunc=<FunctionLikeDeclaration>getContainingFunction(node);
377+
if(!func){
378+
returnundefined;
379+
}
380+
381+
constkeywords:Node[]=[];
382+
383+
if(func.modifiers){
384+
func.modifiers.forEach(modifier=>{
385+
pushKeywordIf(keywords,modifier,SyntaxKind.AsyncKeyword);
386+
});
387+
}
388+
389+
forEachChild(func,aggregate);
390+
391+
returnkeywords;
392+
393+
functionaggregate(node:Node):void{
394+
if(isAwaitExpression(node)){
395+
pushKeywordIf(keywords,node.getFirstToken(),SyntaxKind.AwaitKeyword);
396+
}
397+
// Do not cross function boundaries.
398+
if(!isFunctionLike(node)&&!isClassLike(node)&&!isInterfaceDeclaration(node)&&!isModuleDeclaration(node)&&!isTypeAliasDeclaration(node)&&!isTypeNode(node)){
399+
forEachChild(node,aggregate);
400+
}
401+
}
402+
}
403+
371404
functiongetIfElseOccurrences(ifStatement:IfStatement,sourceFile:SourceFile):HighlightSpan[]{
372405
constkeywords=getIfElseKeywords(ifStatement,sourceFile);
373406
constresult:HighlightSpan[]=[];
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////[|async|] function f() {
4+
//// [|await|] 100;
5+
//// [|a/**/wait|] [|await|] 200;
6+
////class Foo {
7+
//// async memberFunction() {
8+
//// await 1;
9+
////}
10+
////}
11+
//// return [|await|] async function () {
12+
//// await 300;
13+
////}
14+
////}
15+
////async function g() {
16+
//// await 300;
17+
//// async function f() {
18+
//// await 400;
19+
////}
20+
////}
21+
22+
verify.rangesAreOccurrences(false);
23+
24+
goTo.marker();
25+
for(constrangeoftest.ranges()){
26+
verify.occurrencesAtPositionContains(range,false);
27+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////[|a/**/sync|] function f() {
4+
//// [|await|] 100;
5+
//// [|await|] [|await|] 200;
6+
//// return [|await|] async function () {
7+
//// await 300;
8+
////}
9+
////}
10+
11+
verify.rangesAreOccurrences(false);
12+
13+
goTo.marker();
14+
for(constrangeoftest.ranges()){
15+
verify.occurrencesAtPositionContains(range,false);
16+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// Not valid TS ('await' expression is only allowed within an async function.)
4+
5+
////a/**/wait 100;
6+
////async function f() {
7+
//// await 300;
8+
////}
9+
10+
goTo.marker();
11+
verify.occurrencesAtPositionCount(0);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp