-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding documentation.refactor proposed contribution point
For #86788
- Loading branch information
Showing
11 changed files
with
220 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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 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 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
15 changes: 15 additions & 0 deletions
15
extensions/typescript-language-features/src/commands/learnMoreAboutRefactorings.ts
This file contains 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,15 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import * as vscode from 'vscode'; | ||
import { Command } from '../utils/commandManager'; | ||
|
||
export class LearnMoreAboutRefactoringsCommand implements Command { | ||
public readonly id = '_typescript.learnMoreAboutRefactorings'; | ||
|
||
public execute() { | ||
vscode.env.openExternal(vscode.Uri.parse('https://go.microsoft.com/fwlink/?linkid=2114477')); | ||
} | ||
} |
This file contains 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 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 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 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
File renamed without changes.
91 changes: 91 additions & 0 deletions
91
src/vs/workbench/contrib/codeActions/common/documentationContribution.ts
This file contains 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,91 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { CancellationToken } from 'vs/base/common/cancellation'; | ||
import { Disposable } from 'vs/base/common/lifecycle'; | ||
import { Range } from 'vs/editor/common/core/range'; | ||
import { Selection } from 'vs/editor/common/core/selection'; | ||
import { ITextModel } from 'vs/editor/common/model'; | ||
import { CodeAction, CodeActionContext, CodeActionList, CodeActionProvider, CodeActionProviderRegistry } from 'vs/editor/common/modes'; | ||
import { CodeActionKind } from 'vs/editor/contrib/codeAction/types'; | ||
import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; | ||
import { IWorkbenchContribution } from 'vs/workbench/common/contributions'; | ||
import { IExtensionPoint } from 'vs/workbench/services/extensions/common/extensionsRegistry'; | ||
import { DocumentationExtensionPoint } from './documentationExtensionPoint'; | ||
|
||
|
||
export class CodeActionDocumentationContribution extends Disposable implements IWorkbenchContribution, CodeActionProvider { | ||
|
||
private contributions: { | ||
title: string; | ||
when: ContextKeyExpr; | ||
command: string; | ||
}[] = []; | ||
|
||
constructor( | ||
extensionPoint: IExtensionPoint<DocumentationExtensionPoint>, | ||
@IContextKeyService private readonly contextKeyService: IContextKeyService, | ||
) { | ||
super(); | ||
|
||
CodeActionProviderRegistry.register('*', this); | ||
|
||
extensionPoint.setHandler(points => { | ||
this.contributions = []; | ||
for (const documentation of points) { | ||
if (!documentation.value.refactoring) { | ||
continue; | ||
} | ||
|
||
for (const contribution of documentation.value.refactoring) { | ||
const precondition = ContextKeyExpr.deserialize(contribution.when); | ||
if (!precondition) { | ||
continue; | ||
} | ||
|
||
this.contributions.push({ | ||
title: contribution.title, | ||
when: precondition, | ||
command: contribution.command | ||
}); | ||
|
||
} | ||
} | ||
}); | ||
} | ||
|
||
async provideCodeActions(_model: ITextModel, _range: Range | Selection, context: CodeActionContext, _token: CancellationToken): Promise<CodeActionList> { | ||
if (!context.only || !CodeActionKind.Refactor.contains(new CodeActionKind(context.only))) { | ||
return { | ||
actions: [], | ||
dispose: () => { } | ||
}; | ||
} | ||
|
||
const actions: CodeAction[] = []; | ||
|
||
for (const contribution of this.contributions) { | ||
if (!this.contextKeyService.contextMatchesRules(contribution.when)) { | ||
continue; | ||
} | ||
|
||
actions.push({ | ||
title: contribution.title, | ||
kind: CodeActionKind.RefactorDocumentation.value, | ||
command: { | ||
id: contribution.command, | ||
title: contribution.title | ||
} | ||
}); | ||
} | ||
|
||
return { | ||
actions, | ||
dispose: () => { } | ||
}; | ||
} | ||
|
||
public readonly providedCodeActionKinds = [CodeActionKind.RefactorDocumentation.value] as const; | ||
} |
64 changes: 64 additions & 0 deletions
64
src/vs/workbench/contrib/codeActions/common/documentationExtensionPoint.ts
This file contains 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,64 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import * as nls from 'vs/nls'; | ||
import { IConfigurationPropertySchema } from 'vs/platform/configuration/common/configurationRegistry'; | ||
import { languagesExtPoint } from 'vs/workbench/services/mode/common/workbenchModeService'; | ||
|
||
export enum DocumentationExtensionPointFields { | ||
when = 'when', | ||
title = 'title', | ||
command = 'command', | ||
} | ||
|
||
export interface RefactoringDocumentationExtensionPoint { | ||
readonly [DocumentationExtensionPointFields.title]: string; | ||
readonly [DocumentationExtensionPointFields.when]: string; | ||
readonly [DocumentationExtensionPointFields.command]: string; | ||
} | ||
|
||
export interface DocumentationExtensionPoint { | ||
readonly refactoring?: readonly RefactoringDocumentationExtensionPoint[]; | ||
} | ||
|
||
const documentationExtensionPointSchema = Object.freeze<IConfigurationPropertySchema>({ | ||
type: 'object', | ||
description: nls.localize('contributes.documentation', "Contributed documentation."), | ||
properties: { | ||
'refactoring': { | ||
type: 'array', | ||
description: nls.localize('contributes.documentation.refactorings', "Contributed documentation for refactorings."), | ||
items: { | ||
type: 'object', | ||
description: nls.localize('contributes.documentation.refactoring', "Contributed documentation for refactoring."), | ||
required: [ | ||
DocumentationExtensionPointFields.title, | ||
DocumentationExtensionPointFields.when, | ||
DocumentationExtensionPointFields.command | ||
], | ||
properties: { | ||
[DocumentationExtensionPointFields.title]: { | ||
type: 'string', | ||
description: nls.localize('contributes.documentation.refactoring.title', "Label for the documentation used in the UI."), | ||
}, | ||
[DocumentationExtensionPointFields.when]: { | ||
type: 'string', | ||
description: nls.localize('contributes.documentation.refactoring.when', "When clause."), | ||
}, | ||
[DocumentationExtensionPointFields.command]: { | ||
type: 'string', | ||
description: nls.localize('contributes.documentation.refactoring.command', "Command executed."), | ||
}, | ||
}, | ||
} | ||
} | ||
} | ||
}); | ||
|
||
export const documentationExtensionPointDescriptor = { | ||
extensionPoint: 'documentation', | ||
deps: [languagesExtPoint], | ||
jsonSchema: documentationExtensionPointSchema | ||
}; |