-
Notifications
You must be signed in to change notification settings - Fork 38.2k
feat(ts-codeLens): show "implementations" CodeLens for overridden methods #263749 #264546
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cd5348a
ts-codelens: implementations for overrides + test
ritesh006 1d291cd
Merge branch 'main' into test/implementations-codelens
ritesh006 c099047
Update tests and small tweaks
mjbvz c3bcc16
Doc fixes
mjbvz 40fd1d8
Fix string name
mjbvz 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
Some comments aren't visible on the classic Files Changed page.
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
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
169 changes: 169 additions & 0 deletions
169
extensions/typescript-language-features/src/test/smoke/implementationsCodeLens.test.ts
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,169 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All rights reserved. | ||
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| import * as assert from 'assert'; | ||
| import * as vscode from 'vscode'; | ||
| import { disposeAll } from '../../utils/dispose'; | ||
| import { joinLines, withRandomFileEditor } from '../testUtils'; | ||
| import { updateConfig, VsCodeConfiguration } from './referencesCodeLens.test'; | ||
|
|
||
| const Config = { | ||
| referencesCodeLens: 'typescript.referencesCodeLens.enabled', | ||
| implementationsCodeLens: 'typescript.implementationsCodeLens.enabled', | ||
| showOnAllClassMethods: 'typescript.implementationsCodeLens.showOnAllClassMethods', | ||
| }; | ||
|
|
||
| function getCodeLenses(doc: vscode.TextDocument) { | ||
| return vscode.commands.executeCommand<vscode.CodeLens[]>('vscode.executeCodeLensProvider', doc.uri); | ||
| } | ||
|
|
||
| suite('TypeScript Implementations CodeLens', () => { | ||
| const configDefaults = Object.freeze<VsCodeConfiguration>({ | ||
| [Config.referencesCodeLens]: false, | ||
| [Config.implementationsCodeLens]: true, | ||
| [Config.showOnAllClassMethods]: false, | ||
| }); | ||
|
|
||
| const _disposables: vscode.Disposable[] = []; | ||
| let oldConfig: { [key: string]: any } = {}; | ||
|
|
||
| setup(async () => { | ||
| // the tests assume that typescript features are registered | ||
| await vscode.extensions.getExtension('vscode.typescript-language-features')!.activate(); | ||
|
|
||
| // Save off config and apply defaults | ||
| oldConfig = await updateConfig(configDefaults); | ||
| }); | ||
|
|
||
| teardown(async () => { | ||
| disposeAll(_disposables); | ||
|
|
||
| // Restore config | ||
| await updateConfig(oldConfig); | ||
|
|
||
| return vscode.commands.executeCommand('workbench.action.closeAllEditors'); | ||
| }); | ||
|
|
||
| test('Should show on interfaces and abstract classes', async () => { | ||
| await withRandomFileEditor( | ||
| joinLines( | ||
| 'interface IFoo {}', | ||
| 'class Foo implements IFoo {}', | ||
| 'abstract class AbstractBase {}', | ||
| 'class Concrete extends AbstractBase {}' | ||
| ), | ||
| 'ts', | ||
| async (_editor: vscode.TextEditor, doc: vscode.TextDocument) => { | ||
| const lenses = await getCodeLenses(doc); | ||
| assert.strictEqual(lenses?.length, 2); | ||
|
|
||
| assert.strictEqual(lenses?.[0].range.start.line, 0, 'Expected interface IFoo to have a CodeLens'); | ||
| assert.strictEqual(lenses?.[1].range.start.line, 2, 'Expected abstract class AbstractBase to have a CodeLens'); | ||
| }, | ||
| ); | ||
| }); | ||
|
|
||
| test('Should show on abstract methods, properties, and getters', async () => { | ||
| await withRandomFileEditor( | ||
| joinLines( | ||
| 'abstract class Base {', | ||
| ' abstract method(): void;', | ||
| ' abstract property: string;', | ||
| ' abstract get getter(): number;', | ||
| '}', | ||
| 'class Derived extends Base {', | ||
| ' method() {}', | ||
| ' property = "test";', | ||
| ' get getter() { return 42; }', | ||
| '}', | ||
| ), | ||
| 'ts', | ||
| async (_editor: vscode.TextEditor, doc: vscode.TextDocument) => { | ||
| const lenses = await getCodeLenses(doc); | ||
| assert.strictEqual(lenses?.length, 4); | ||
|
|
||
| assert.strictEqual(lenses?.[0].range.start.line, 0, 'Expected abstract class to have a CodeLens'); | ||
| assert.strictEqual(lenses?.[1].range.start.line, 1, 'Expected abstract method to have a CodeLens'); | ||
| assert.strictEqual(lenses?.[2].range.start.line, 2, 'Expected abstract property to have a CodeLens'); | ||
| assert.strictEqual(lenses?.[3].range.start.line, 3, 'Expected abstract getter to have a CodeLens'); | ||
| }, | ||
| ); | ||
| }); | ||
|
|
||
| test('Should not show implementations on methods by default', async () => { | ||
| await withRandomFileEditor( | ||
| joinLines( | ||
| 'abstract class A {', | ||
| ' foo() {}', | ||
| '}', | ||
| 'class B extends A {', | ||
| ' foo() {}', | ||
| '}', | ||
| ), | ||
| 'ts', | ||
| async (_editor: vscode.TextEditor, doc: vscode.TextDocument) => { | ||
| const lenses = await getCodeLenses(doc); | ||
| assert.strictEqual(lenses?.length, 1); | ||
| }, | ||
| ); | ||
| }); | ||
|
|
||
| test('should show on all methods when showOnAllClassMethods is enabled', async () => { | ||
| await updateConfig({ | ||
| [Config.showOnAllClassMethods]: true | ||
| }); | ||
|
|
||
| await withRandomFileEditor( | ||
| joinLines( | ||
| 'abstract class A {', | ||
| ' foo() {}', | ||
| '}', | ||
| 'class B extends A {', | ||
| ' foo() {}', | ||
| '}', | ||
| ), | ||
| 'ts', | ||
| async (_editor: vscode.TextEditor, doc: vscode.TextDocument) => { | ||
| const lenses = await getCodeLenses(doc); | ||
| assert.strictEqual(lenses?.length, 3); | ||
|
|
||
| assert.strictEqual(lenses?.[0].range.start.line, 0, 'Expected class A to have a CodeLens'); | ||
| assert.strictEqual(lenses?.[1].range.start.line, 1, 'Expected method A.foo to have a CodeLens'); | ||
| assert.strictEqual(lenses?.[2].range.start.line, 4, 'Expected method B.foo to have a CodeLens'); | ||
| }, | ||
| ); | ||
| }); | ||
|
|
||
| test('should not show on private methods when showOnAllClassMethods is enabled', async () => { | ||
| await updateConfig({ | ||
| [Config.showOnAllClassMethods]: true | ||
| }); | ||
|
|
||
| await withRandomFileEditor( | ||
| joinLines( | ||
| 'abstract class A {', | ||
| ' public foo() {}', | ||
| ' private bar() {}', | ||
| ' protected baz() {}', | ||
| '}', | ||
| 'class B extends A {', | ||
| ' public foo() {}', | ||
| ' protected baz() {}', | ||
| '}', | ||
| ), | ||
| 'ts', | ||
| async (_editor: vscode.TextEditor, doc: vscode.TextDocument) => { | ||
| const lenses = await getCodeLenses(doc); | ||
| assert.strictEqual(lenses?.length, 5); | ||
|
|
||
| assert.strictEqual(lenses?.[0].range.start.line, 0, 'Expected class A to have a CodeLens'); | ||
| assert.strictEqual(lenses?.[1].range.start.line, 1, 'Expected method A.foo to have a CodeLens'); | ||
| assert.strictEqual(lenses?.[2].range.start.line, 3, 'Expected method A.baz to have a CodeLens'); | ||
| assert.strictEqual(lenses?.[3].range.start.line, 6, 'Expected method B.foo to have a CodeLens'); | ||
| assert.strictEqual(lenses?.[4].range.start.line, 7, 'Expected method B.baz to have a CodeLens'); | ||
| }, | ||
| ); | ||
| }); | ||
| }); |
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.
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.
We should skip showing these on private methods as these cannot be overridden