-
Notifications
You must be signed in to change notification settings - Fork 734
Fix JSDoc inheritance for overridden methods and properties in hover #2036
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
Draft
Copilot
wants to merge
4
commits into
main
Choose a base branch
from
copilot/fix-hover-jsdoc-comments
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| package fourslash_test | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/microsoft/typescript-go/internal/fourslash" | ||
| "github.com/microsoft/typescript-go/internal/testutil" | ||
| ) | ||
|
|
||
| func TestHoverInheritedJSDocInterface(t *testing.T) { | ||
| t.Parallel() | ||
| defer testutil.RecoverAndFail(t, "Panic on fourslash test") | ||
| const content = ` | ||
| interface foo { | ||
| /** base jsdoc */ | ||
| bar(k: string): number; | ||
| /** other jsdoc */ | ||
| other: 24; | ||
| } | ||
|
|
||
| interface bar extends foo { | ||
| bar(k: string | symbol): number | 99; | ||
| } | ||
|
|
||
| declare const f: foo; | ||
| declare const b: bar; | ||
|
|
||
| f./*1*/bar; | ||
| f./*2*/other; | ||
| b./*3*/bar; | ||
| b./*4*/other; | ||
| ` | ||
| f := fourslash.NewFourslash(t, nil /*capabilities*/, content) | ||
| f.VerifyBaselineHover(t) | ||
| } | ||
|
|
||
| func TestHoverInheritedJSDocClass(t *testing.T) { | ||
| t.Parallel() | ||
| defer testutil.RecoverAndFail(t, "Panic on fourslash test") | ||
| const content = ` | ||
| declare class thing { | ||
| /** doc comment */ | ||
| method(s: string): void; | ||
| } | ||
|
|
||
| declare class potato extends thing { | ||
| method(s: "1234"): void; | ||
| } | ||
|
|
||
| declare const t: thing; | ||
| declare const p: potato; | ||
|
|
||
| t./*1*/method; | ||
| p./*2*/method; | ||
| ` | ||
| f := fourslash.NewFourslash(t, nil /*capabilities*/, content) | ||
| // t.method should show "doc comment" | ||
| f.VerifyQuickInfoAt(t, "1", "(method) thing.method(s: string): void", "doc comment") | ||
| // p.method should inherit "doc comment" from thing | ||
| f.VerifyQuickInfoAt(t, "2", "(method) potato.method(s: \"1234\"): void", "doc comment") | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
159 changes: 159 additions & 0 deletions
159
testdata/baselines/reference/fourslash/quickInfo/hoverInheritedJSDocInterface.baseline
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| // === QuickInfo === | ||
| === /hoverInheritedJSDocInterface.ts === | ||
| // interface foo { | ||
| // /** base jsdoc */ | ||
| // bar(k: string): number; | ||
| // /** other jsdoc */ | ||
| // other: 24; | ||
| // } | ||
| // | ||
| // interface bar extends foo { | ||
| // bar(k: string | symbol): number | 99; | ||
| // } | ||
| // | ||
| // declare const f: foo; | ||
| // declare const b: bar; | ||
| // | ||
| // f.bar; | ||
| // ^^^ | ||
| // | ---------------------------------------------------------------------- | ||
| // | ```tsx | ||
| // | (method) foo.bar(k: string): number | ||
| // | ``` | ||
| // | base jsdoc | ||
| // | ---------------------------------------------------------------------- | ||
| // f.other; | ||
| // ^^^^^ | ||
| // | ---------------------------------------------------------------------- | ||
| // | ```tsx | ||
| // | (property) foo.other: 24 | ||
| // | ``` | ||
| // | other jsdoc | ||
| // | ---------------------------------------------------------------------- | ||
| // b.bar; | ||
| // ^^^ | ||
| // | ---------------------------------------------------------------------- | ||
| // | ```tsx | ||
| // | (method) bar.bar(k: string | symbol): number | ||
| // | ``` | ||
| // | base jsdoc | ||
| // | ---------------------------------------------------------------------- | ||
| // b.other; | ||
| // ^^^^^ | ||
| // | ---------------------------------------------------------------------- | ||
| // | ```tsx | ||
| // | (property) foo.other: 24 | ||
| // | ``` | ||
| // | other jsdoc | ||
| // | ---------------------------------------------------------------------- | ||
| // | ||
| [ | ||
| { | ||
| "marker": { | ||
| "Position": 217, | ||
| "LSPosition": { | ||
| "line": 14, | ||
| "character": 2 | ||
| }, | ||
| "Name": "1", | ||
| "Data": {} | ||
| }, | ||
| "item": { | ||
| "contents": { | ||
| "kind": "markdown", | ||
| "value": "```tsx\n(method) foo.bar(k: string): number\n```\nbase jsdoc" | ||
| }, | ||
| "range": { | ||
| "start": { | ||
| "line": 14, | ||
| "character": 2 | ||
| }, | ||
| "end": { | ||
| "line": 14, | ||
| "character": 5 | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| "marker": { | ||
| "Position": 224, | ||
| "LSPosition": { | ||
| "line": 15, | ||
| "character": 2 | ||
| }, | ||
| "Name": "2", | ||
| "Data": {} | ||
| }, | ||
| "item": { | ||
| "contents": { | ||
| "kind": "markdown", | ||
| "value": "```tsx\n(property) foo.other: 24\n```\nother jsdoc" | ||
| }, | ||
| "range": { | ||
| "start": { | ||
| "line": 15, | ||
| "character": 2 | ||
| }, | ||
| "end": { | ||
| "line": 15, | ||
| "character": 7 | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| "marker": { | ||
| "Position": 233, | ||
| "LSPosition": { | ||
| "line": 16, | ||
| "character": 2 | ||
| }, | ||
| "Name": "3", | ||
| "Data": {} | ||
| }, | ||
| "item": { | ||
| "contents": { | ||
| "kind": "markdown", | ||
| "value": "```tsx\n(method) bar.bar(k: string | symbol): number\n```\nbase jsdoc" | ||
| }, | ||
| "range": { | ||
| "start": { | ||
| "line": 16, | ||
| "character": 2 | ||
| }, | ||
| "end": { | ||
| "line": 16, | ||
| "character": 5 | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| "marker": { | ||
| "Position": 240, | ||
| "LSPosition": { | ||
| "line": 17, | ||
| "character": 2 | ||
| }, | ||
| "Name": "4", | ||
| "Data": {} | ||
| }, | ||
| "item": { | ||
| "contents": { | ||
| "kind": "markdown", | ||
| "value": "```tsx\n(property) foo.other: 24\n```\nother jsdoc" | ||
| }, | ||
| "range": { | ||
| "start": { | ||
| "line": 17, | ||
| "character": 2 | ||
| }, | ||
| "end": { | ||
| "line": 17, | ||
| "character": 7 | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot This function does not exist in the old codebase. What does this code correspond to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This corresponds to the
findBaseOfDeclarationfunction insrc/services/services.ts(lines ~3565-3575 in the TypeScript codebase).The TypeScript implementation:
Our Go implementation achieves the same goal: traverse base types to find JSDoc from parent declarations when the current declaration lacks documentation.