Skip to content

getSymbolAtLocation now supports class expressions#51049

Closed
sandersn wants to merge 6 commits into
mainfrom
getTypeAtLocation-support-class-expr
Closed

getSymbolAtLocation now supports class expressions#51049
sandersn wants to merge 6 commits into
mainfrom
getTypeAtLocation-support-class-expr

Conversation

@sandersn

@sandersn sandersn commented Oct 3, 2022

Copy link
Copy Markdown
Member

Discovered while writing #51016; after that merges I'll update this PR to remove its special-case code.

  1. Many baselines change because our symbol baselines apparently use getSymbolAtLocation. I believe that class expressions will also show up better in quick info, although I'm not sure. This is a big change, but I think it's good.
  2. Some special-case code in find-all-refs is no longer relevant. (and more from Fix crash in goto-def on @override #51016 will be when that merges.)
  3. Using the real symbol gives names to more class expressions, so I made the expression more complex to keep the class truly anonymous in
    goToImplementationInterface_07. The quick info display also changes, from
(anonymous local class)

to

(local class) (Anonymous class)

This is more consistent with named class expressions ((local class) C), so I think it's a good change.

And accept baselines for later inspection.

One fourslash test changes, indicating that quick info relied on
getTypeAtLocation not returning anything for class expressions to
distinguish named from anonymous class expressions. This predicate will
have to be improved.
1. Some special-case code in find-all-refs is no longer relevant.
2. Using the real symbol gives names to more class expressions, so I
made the expression more complex to keep the class truly anonymous in
goToImplementationInterface_07. The quick info display also changes,
from

```
(anonymous local class)
```

to

```
(local class) (Anonymous class)
```

This is more consistent internally and externally, so I think it's a
good change.
@typescript-bot typescript-bot added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Oct 3, 2022
@sandersn

sandersn commented Oct 3, 2022

Copy link
Copy Markdown
Member Author

@amcasey and @andrewbranch I think you know the most about how this will affect language service results.

Comment thread tests/cases/fourslash/goToImplementationInterface_07.ts Outdated
Only display `(local class)` if the class expression is named and has no
alias. Other named classes use the normal `class C` format; anonymous
classes display `(Anonymous class)`.
@amcasey

amcasey commented Oct 5, 2022

Copy link
Copy Markdown
Member

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

@typescript-bot

typescript-bot commented Oct 5, 2022

Copy link
Copy Markdown
Contributor

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

Update: The results are in!

@typescript-bot

typescript-bot commented Oct 5, 2022

Copy link
Copy Markdown
Contributor

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

Update: The results are in!

@typescript-bot

Copy link
Copy Markdown
Contributor

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

Everything looks good!

@amcasey

amcasey commented Oct 5, 2022

Copy link
Copy Markdown
Member

So, I have basically no idea what impact this will have but, superficially, it looks completely out of place in the list of pre-existing syntax kind checks. If it was always an oversight (doesn't really look like it?), why wouldn't we do the same for function expressions?

@typescript-bot

Copy link
Copy Markdown
Contributor

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

Something interesting changed - please have a look.

Details

felixrieseberg/windows95

⚠️ Note that built also had errors ⚠️
Req #432 - references
    at formatMessage (/typescript-main/built/local/tsserver.js:178948:29)
    at IOSession.Session.writeMessage (/typescript-main/built/local/tsserver.js:180023:31)
    at IOSession.Session.send (/typescript-main/built/local/tsserver.js:180020:22)
    at IOSession.Session.doOutput (/typescript-main/built/local/tsserver.js:180073:22)
    at IOSession.Session.onMessage (/typescript-main/built/local/tsserver.js:181718:30)
    at Interface.<anonymous> (/typescript-main/built/local/tsserver.js:185825:31)
Req #432 - references
    at formatMessage (/typescript-51049/built/local/tsserver.js:178949:29)
    at IOSession.Session.writeMessage (/typescript-51049/built/local/tsserver.js:180024:31)
    at IOSession.Session.send (/typescript-51049/built/local/tsserver.js:180021:22)
    at IOSession.Session.doOutput (/typescript-51049/built/local/tsserver.js:180074:22)
    at IOSession.Session.onMessage (/typescript-51049/built/local/tsserver.js:181719:30)
    at Interface.<anonymous> (/typescript-51049/built/local/tsserver.js:185826:31)

Last few requests

{"seq":429,"type":"request","command":"completionInfo","arguments":{"file":"@PROJECT_ROOT@/src/renderer/lib/_libwabt.js","line":13,"offset":76180,"includeExternalModuleExports":false,"includeInsertTextCompletions":true,"triggerKind":1}}
{"seq":430,"type":"request","command":"completionEntryDetails","arguments":{"file":"@PROJECT_ROOT@/src/renderer/lib/_libwabt.js","line":13,"offset":76180,"entryNames":["_"]}}
{"seq":431,"type":"request","command":"definitionAndBoundSpan","arguments":{"file":"@PROJECT_ROOT@/src/renderer/lib/_libwabt.js","line":13,"offset":77944}}
{"seq":432,"type":"request","command":"references","arguments":{"file":"@PROJECT_ROOT@/src/renderer/lib/_libwabt.js","line":13,"offset":78089}}

Repro Steps

  1. git clone https://github.com/felixrieseberg/windows95 --recurse-submodules
  2. In dir windows95, run git reset --hard c483871df905ac8889090d03afeae4f864d2c313
  3. In dir windows95, run yarn install --ignore-engines --ignore-scripts --silent
  4. Back in the initial folder, download RepoResults4/felixrieseberg.windows95.replay.txt from the artifact folder
  5. npm install --no-save @typescript/server-replay
  6. npx tsreplay ./windows95 ./felixrieseberg.windows95.replay.txt path/to/tsserver.js
  7. npx tsreplay --help to learn about helpful switches for debugging, logging, etc

palantir/blueprint

⚠️ Note that built also had errors ⚠️
Req #12285 - references
    at formatMessage (/typescript-main/built/local/tsserver.js:178948:29)
    at IOSession.Session.writeMessage (/typescript-main/built/local/tsserver.js:180023:31)
    at IOSession.Session.send (/typescript-main/built/local/tsserver.js:180020:22)
    at IOSession.Session.doOutput (/typescript-main/built/local/tsserver.js:180073:22)
    at IOSession.Session.onMessage (/typescript-main/built/local/tsserver.js:181718:30)
    at Interface.<anonymous> (/typescript-main/built/local/tsserver.js:185825:31)
Req #12285 - references
    at formatMessage (/typescript-51049/built/local/tsserver.js:178949:29)
    at IOSession.Session.writeMessage (/typescript-51049/built/local/tsserver.js:180024:31)
    at IOSession.Session.send (/typescript-51049/built/local/tsserver.js:180021:22)
    at IOSession.Session.doOutput (/typescript-51049/built/local/tsserver.js:180074:22)
    at IOSession.Session.onMessage (/typescript-51049/built/local/tsserver.js:181719:30)
    at Interface.<anonymous> (/typescript-51049/built/local/tsserver.js:185826:31)

Last few requests

{"seq":12282,"type":"request","command":"completionInfo","arguments":{"file":"@PROJECT_ROOT@/site/docs/versions/1/docs-app.js","line":1,"offset":403366,"includeExternalModuleExports":false,"includeInsertTextCompletions":true,"triggerKind":2,"triggerCharacter":"."}}
{"seq":12283,"type":"request","command":"definitionAndBoundSpan","arguments":{"file":"@PROJECT_ROOT@/site/docs/versions/1/docs-app.js","line":1,"offset":404323}}
{"seq":12284,"type":"request","command":"definitionAndBoundSpan","arguments":{"file":"@PROJECT_ROOT@/site/docs/versions/1/docs-app.js","line":1,"offset":405053}}
{"seq":12285,"type":"request","command":"references","arguments":{"file":"@PROJECT_ROOT@/site/docs/versions/1/docs-app.js","line":1,"offset":405913}}

Repro Steps

  1. git clone https://github.com/palantir/blueprint --recurse-submodules
  2. In dir blueprint, run git reset --hard 5b06fd3e9740675869c043ee8505c4927afe6e72
  3. In dir blueprint, run yarn install --ignore-engines --ignore-scripts --silent
  4. Back in the initial folder, download RepoResults4/palantir.blueprint.replay.txt from the artifact folder
  5. npm install --no-save @typescript/server-replay
  6. npx tsreplay ./blueprint ./palantir.blueprint.replay.txt path/to/tsserver.js
  7. npx tsreplay --help to learn about helpful switches for debugging, logging, etc

@amcasey

amcasey commented Oct 5, 2022

Copy link
Copy Markdown
Member

@sandersn The new server errors aren't related or interesting.

@sandersn

sandersn commented Oct 7, 2022

Copy link
Copy Markdown
Member Author

it looks completely out of place in the list of pre-existing syntax kind checks

From discussion on teams, getSymbolAtLocation currently only handles identifiers and some other keywords -- all single tokens. It seems likely that some other entrypoint handles symbols of other things like expressions, and that that's the right place for class expressions.

@andrewbranch

Copy link
Copy Markdown
Member

I’d be interested to read the discussion on Teams I missed, because my assumption would have been that this:

getSymbolAtLocation currently only handles identifiers and some other keywords -- all single tokens

is just an artifact of its usage in the services for things like quick info, where the cursor is necessarily confined to a single token. As an API entrypoint, I always understood its failure on higher nodes to be undesirable.

@amcasey

amcasey commented Oct 19, 2022

Copy link
Copy Markdown
Member

@andrewbranch We just spoke 1:1. Neither of us had any context on what the function was supposed to do, but I observed that all the existing checks were for tokens, suggesting that expressions were handled elsewhere (or, alternatively, that several kinds of expressions needed to be supported).

@sandersn

Copy link
Copy Markdown
Member Author

Overall, the benefit of getting rid of a couple of special cases in the services vs. changing the way getSymbolAtLocation works isn't justified. I'm going to close this for now.

@sandersn sandersn closed this Oct 19, 2022
@sandersn

Copy link
Copy Markdown
Member Author

Overall, the benefit of getting rid of a couple of special cases in the services vs. changing the way getSymbolAtLocation works isn't justified. I'm going to close this for now.

@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

5 participants