Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip invalid completion check immediately after newline #55061

Merged
merged 18 commits into from
Nov 20, 2023

Conversation

suica
Copy link
Contributor

@suica suica commented Jul 18, 2023

Fixes #54729

Demo:
completion

@typescript-bot typescript-bot added the For Milestone Bug PRs that fix a bug with a specific milestone label Jul 18, 2023
@suica
Copy link
Contributor Author

suica commented Jul 18, 2023

@microsoft-github-policy-service agree

@suica suica marked this pull request as ready for review July 18, 2023 15:46
@svipas
Copy link

svipas commented Nov 7, 2023

@sandersn could we expect this to be in TypeScript 5.3 or at least in 5.4? This is really needed for DX.

@iisaduan
Copy link
Member

iisaduan commented Nov 8, 2023

@typescript-bot pack this

4 similar comments
@iisaduan

This comment was marked as duplicate.

@iisaduan

This comment was marked as duplicate.

@iisaduan

This comment was marked as duplicate.

@gabritto
Copy link
Member

@typescript-bot pack this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Nov 10, 2023

Heya @gabritto, I've started to run the tarball bundle task on this PR at 6eb4ff3. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Nov 10, 2023

Hey @gabritto, I've packed this into an installable tgz. You can install it for testing by referencing it in your package.json like so:

{
    "devDependencies": {
        "typescript": "https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/158553/artifacts?artifactName=tgz&fileId=39BD9E9D5446EBD2B72515AE8DB4BF764C12AF5B973FEDCDD9CD2BDC8E28119502&fileName=/typescript-5.4.0-insiders.20231110.tgz"
    }
}

and then running npm install.


There is also a playground for this build and an npm module you can use via "typescript": "npm:@typescript-deploys/[email protected]".;

@suica
Copy link
Contributor Author

suica commented Nov 11, 2023

cool

@zardoy
Copy link
Contributor

zardoy commented Nov 11, 2023

absolutely insane

@gabritto

This comment was marked as duplicate.

@gabritto
Copy link
Member

@typescript-bot user test tsserver
@typescript-bot test tsserver top100
@typescript-bot perf test this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Nov 15, 2023

Heya @gabritto, I've started to run the diff-based user code test suite (tsserver) on this PR at 6eb4ff3. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Nov 15, 2023

Heya @gabritto, I've started to run the regular perf test suite on this PR at 6eb4ff3. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Nov 15, 2023

Heya @gabritto, I've started to run the diff-based top-repos suite (tsserver) on this PR at 6eb4ff3. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

@gabritto Here are the results of running the user test suite comparing main and refs/pull/55061/merge:

Everything looks good!

function isCompletionListBlocker(contextToken: Node): boolean {
const start = timestamp();
const result = isInStringOrRegularExpressionOrTemplateLiteral(contextToken) ||
isSolelyIdentifierDefinitionLocation(contextToken) ||
// GH#54729 ignore this case when current position is in a newline
Copy link
Member

@gabritto gabritto Nov 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, if we wanted to be more precise in when we allow completions, this check of isInDifferentLineWithContextToken should be done inside isSolelyIdentifierDefinitionLocation, and should be done case-by-case, because I don't think we want to allow completions in a newline for every possible case isSolelyIdentifierDefinitionLocation returns true.

For instance, isSolelyIdentifierDefinitionLocation returns true on the following position:

var [x, y
|

It doesn't look like you'd actually want completions at that position.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Tried to fix this, @gabritto plz take a look at the new code :)

Copy link
Member

@iisaduan iisaduan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution, and I apologize for the spam while trying to get the bot to work!

The change in general seems good, but we should probably use the check to alter isSolelyIdentifierDefinitionLocation instead of patching over its result.

src/services/completions.ts Outdated Show resolved Hide resolved
Comment on lines 4071 to 4072
// GH#54729 ignore this case when current position is in a newline
(isSolelyIdentifierDefinitionLocation(contextToken) && !isInDifferentLineWithContextToken(contextToken, position)) ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// GH#54729 ignore this case when current position is in a newline
(isSolelyIdentifierDefinitionLocation(contextToken) && !isInDifferentLineWithContextToken(contextToken, position)) ||
isSolelyIdentifierDefinitionLocation(contextToken) ||

IMO it makes more sense to put the isInDifferentLineWithContextToken check into the return statement of isSolelyIdentifierDefinitionLocation, so we don't unblock too many cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! gonna fix it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, and now the logic looks less messy

src/services/completions.ts Outdated Show resolved Hide resolved
@typescript-bot
Copy link
Collaborator

@gabritto
The results of the perf run you requested are in!

Here they are:

Compiler

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
Angular - node (v18.15.0, x64)
Memory used 295,159k (± 0.01%) 295,185k (± 0.02%) ~ 295,118k 295,244k p=0.378 n=6
Parse Time 2.64s (± 0.28%) 2.64s (± 0.44%) ~ 2.62s 2.65s p=0.734 n=6
Bind Time 0.82s (± 0.00%) 0.83s (± 0.99%) ~ 0.82s 0.84s p=0.073 n=6
Check Time 8.05s (± 0.19%) 8.04s (± 0.36%) ~ 8.00s 8.07s p=0.405 n=6
Emit Time 7.08s (± 0.27%) 7.08s (± 0.27%) ~ 7.06s 7.11s p=1.000 n=6
Total Time 18.59s (± 0.17%) 18.58s (± 0.18%) ~ 18.53s 18.62s p=0.628 n=6
Compiler-Unions - node (v18.15.0, x64)
Memory used 193,629k (± 1.67%) 192,664k (± 1.59%) ~ 190,677k 196,736k p=1.000 n=6
Parse Time 1.36s (± 1.38%) 1.34s (± 1.19%) ~ 1.31s 1.35s p=0.318 n=6
Bind Time 0.72s (± 0.00%) 0.72s (± 0.00%) ~ 0.72s 0.72s p=1.000 n=6
Check Time 9.16s (± 0.41%) 9.20s (± 0.39%) ~ 9.15s 9.25s p=0.063 n=6
Emit Time 2.62s (± 0.75%) 2.62s (± 0.39%) ~ 2.61s 2.63s p=1.000 n=6
Total Time 13.85s (± 0.34%) 13.88s (± 0.26%) ~ 13.83s 13.93s p=0.228 n=6
Monaco - node (v18.15.0, x64)
Memory used 347,353k (± 0.00%) 347,352k (± 0.00%) ~ 347,328k 347,369k p=0.810 n=6
Parse Time 2.46s (± 0.31%) 2.46s (± 0.50%) ~ 2.44s 2.47s p=0.315 n=6
Bind Time 0.93s (± 0.59%) 0.93s (± 0.56%) ~ 0.92s 0.93s p=0.640 n=6
Check Time 6.92s (± 0.46%) 6.91s (± 0.44%) ~ 6.89s 6.97s p=0.685 n=6
Emit Time 4.07s (± 0.72%) 4.05s (± 0.70%) ~ 4.02s 4.10s p=0.222 n=6
Total Time 14.37s (± 0.31%) 14.34s (± 0.31%) ~ 14.30s 14.42s p=0.296 n=6
TFS - node (v18.15.0, x64)
Memory used 302,613k (± 0.00%) 302,621k (± 0.01%) ~ 302,590k 302,643k p=0.297 n=6
Parse Time 2.01s (± 1.27%) 2.01s (± 1.08%) ~ 1.98s 2.04s p=0.809 n=6
Bind Time 1.01s (± 1.32%) 1.00s (± 1.09%) ~ 0.99s 1.02s p=0.209 n=6
Check Time 6.26s (± 0.41%) 6.28s (± 0.57%) ~ 6.22s 6.32s p=0.372 n=6
Emit Time 3.58s (± 0.33%) 3.58s (± 0.43%) ~ 3.56s 3.60s p=0.869 n=6
Total Time 12.86s (± 0.32%) 12.86s (± 0.35%) ~ 12.81s 12.91s p=1.000 n=6
material-ui - node (v18.15.0, x64)
Memory used 470,552k (± 0.01%) 470,558k (± 0.00%) ~ 470,543k 470,572k p=0.470 n=6
Parse Time 2.56s (± 0.21%) 2.57s (± 1.08%) ~ 2.54s 2.62s p=0.866 n=6
Bind Time 0.99s (± 1.18%) 0.99s (± 0.90%) ~ 0.98s 1.00s p=0.933 n=6
Check Time 16.66s (± 0.33%) 16.64s (± 0.32%) ~ 16.55s 16.70s p=0.574 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 20.22s (± 0.29%) 20.19s (± 0.30%) ~ 20.08s 20.23s p=0.808 n=6
xstate - node (v18.15.0, x64)
Memory used 512,810k (± 0.01%) 512,834k (± 0.01%) ~ 512,773k 512,911k p=0.470 n=6
Parse Time 3.28s (± 0.42%) 3.27s (± 0.27%) ~ 3.26s 3.28s p=0.562 n=6
Bind Time 1.54s (± 0.26%) 1.54s (± 0.33%) ~ 1.54s 1.55s p=0.595 n=6
Check Time 2.87s (± 0.84%) 2.86s (± 0.57%) ~ 2.84s 2.88s p=0.746 n=6
Emit Time 0.08s (± 4.99%) 0.08s (± 6.19%) ~ 0.08s 0.09s p=0.595 n=6
Total Time 7.76s (± 0.23%) 7.76s (± 0.21%) ~ 7.74s 7.78s p=0.683 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • Angular - node (v18.15.0, x64)
  • Compiler-Unions - node (v18.15.0, x64)
  • Monaco - node (v18.15.0, x64)
  • TFS - node (v18.15.0, x64)
  • material-ui - node (v18.15.0, x64)
  • xstate - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

tsserver

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
Compiler-UnionsTSServer - node (v18.15.0, x64)
Req 1 - updateOpen 2,365ms (± 0.63%) 2,373ms (± 1.16%) ~ 2,342ms 2,412ms p=0.689 n=6
Req 2 - geterr 5,389ms (± 1.51%) 5,376ms (± 1.73%) ~ 5,303ms 5,498ms p=1.000 n=6
Req 3 - references 326ms (± 0.74%) 329ms (± 1.14%) ~ 325ms 334ms p=0.195 n=6
Req 4 - navto 277ms (± 1.09%) 277ms (± 0.80%) ~ 274ms 279ms p=0.934 n=6
Req 5 - completionInfo count 1,356 (± 0.00%) 1,356 (± 0.00%) ~ 1,356 1,356 p=1.000 n=6
Req 5 - completionInfo 85ms (± 7.04%) 81ms (± 8.68%) ~ 75ms 90ms p=0.366 n=6
CompilerTSServer - node (v18.15.0, x64)
Req 1 - updateOpen 2,489ms (± 0.50%) 2,505ms (± 0.81%) ~ 2,467ms 2,522ms p=0.128 n=6
Req 2 - geterr 4,103ms (± 1.87%) 4,081ms (± 2.05%) ~ 4,018ms 4,201ms p=0.810 n=6
Req 3 - references 338ms (± 1.60%) 341ms (± 1.58%) ~ 333ms 345ms p=0.744 n=6
Req 4 - navto 283ms (± 0.30%) 283ms (± 0.45%) ~ 281ms 284ms p=0.445 n=6
Req 5 - completionInfo count 1,518 (± 0.00%) 1,518 (± 0.00%) ~ 1,518 1,518 p=1.000 n=6
Req 5 - completionInfo 79ms (± 7.32%) 86ms (± 6.57%) 🔻+8ms (+ 9.51%) 79ms 90ms p=0.037 n=6
xstateTSServer - node (v18.15.0, x64)
Req 1 - updateOpen 2,605ms (± 0.48%) 2,595ms (± 0.45%) ~ 2,575ms 2,609ms p=0.336 n=6
Req 2 - geterr 1,729ms (± 1.90%) 1,711ms (± 2.26%) ~ 1,664ms 1,752ms p=0.378 n=6
Req 3 - references 115ms (± 6.44%) 122ms (± 3.19%) ~ 117ms 126ms p=0.076 n=6
Req 4 - navto 366ms (± 0.51%) 366ms (± 0.54%) ~ 364ms 369ms p=0.625 n=6
Req 5 - completionInfo count 2,073 (± 0.00%) 2,073 (± 0.00%) ~ 2,073 2,073 p=1.000 n=6
Req 5 - completionInfo 311ms (± 1.75%) 304ms (± 2.60%) ~ 298ms 318ms p=0.092 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • CompilerTSServer - node (v18.15.0, x64)
  • Compiler-UnionsTSServer - node (v18.15.0, x64)
  • xstateTSServer - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Startup

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
tsc-startup - node (v18.15.0, x64)
Execution time 152.61ms (± 0.20%) 152.50ms (± 0.18%) -0.11ms (- 0.07%) 151.45ms 155.65ms p=0.000 n=600
tsserver-startup - node (v18.15.0, x64)
Execution time 227.41ms (± 0.15%) 227.36ms (± 0.16%) ~ 226.13ms 233.49ms p=0.053 n=600
tsserverlibrary-startup - node (v18.15.0, x64)
Execution time 229.32ms (± 0.16%) 229.36ms (± 0.17%) ~ 227.64ms 235.40ms p=0.263 n=600
typescript-startup - node (v18.15.0, x64)
Execution time 228.96ms (± 0.15%) 228.98ms (± 0.19%) ~ 227.51ms 235.45ms p=0.460 n=600
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • tsc-startup - node (v18.15.0, x64)
  • tsserver-startup - node (v18.15.0, x64)
  • tsserverlibrary-startup - node (v18.15.0, x64)
  • typescript-startup - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Developer Information:

Download Benchmarks

@typescript-bot
Copy link
Collaborator

@gabritto Here are the results of running the top-repos suite comparing main and refs/pull/55061/merge:

Everything looks good!

@suica suica requested a review from iisaduan November 17, 2023 05:55
Copy link
Member

@iisaduan iisaduan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Note: this change only adds the newline after variable declarations

@iisaduan iisaduan merged commit ffc21e5 into microsoft:main Nov 20, 2023
19 checks passed
@svipas
Copy link

svipas commented Nov 21, 2023

@iisaduan Thank you for merging it. And, @suica for fixing the issue. 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Milestone Bug PRs that fix a bug with a specific milestone
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Should not block completions when let a on the previous line
7 participants