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

move SnippetTextEdit into vscode-dts #160408

Merged
merged 5 commits into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/vs/workbench/api/common/extHostBulkEdits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@ export class ExtHostBulkEdits {
}

applyWorkspaceEdit(edit: vscode.WorkspaceEdit, extension: IExtensionDescription, isRefactoring?: boolean): Promise<boolean> {
const allowSnippetTextEdit = isProposedApiEnabled(extension, 'snippetWorkspaceEdit');
const allowIsRefactoring = isProposedApiEnabled(extension, 'workspaceEditIsRefactoring');
if (isRefactoring && !allowIsRefactoring) {
console.warn(`Extension '${extension.identifier.value}' uses a proposed API 'workspaceEditIsRefactoring' which is NOT enabled for it`);
isRefactoring = undefined;
}
const dto = WorkspaceEdit.from(edit, this._versionInformationProvider, allowSnippetTextEdit);
const dto = WorkspaceEdit.from(edit, this._versionInformationProvider);
return this._proxy.$tryApplyWorkspaceEdit(dto, undefined, isRefactoring);
}
}
5 changes: 2 additions & 3 deletions src/vs/workbench/api/common/extHostFileSystemEventService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { FileOperation } from 'vs/platform/files/common/files';
import { CancellationToken } from 'vs/base/common/cancellation';
import { ILogService } from 'vs/platform/log/common/log';
import { IExtHostWorkspace } from 'vs/workbench/api/common/extHostWorkspace';
import { isProposedApiEnabled } from 'vs/workbench/services/extensions/common/extensions';

class FileSystemWatcher implements vscode.FileSystemWatcher {

Expand Down Expand Up @@ -250,11 +249,11 @@ export class ExtHostFileSystemEventService implements ExtHostFileSystemEventServ

// concat all WorkspaceEdits collected via waitUntil-call and send them over to the renderer
const dto: IWorkspaceEditDto = { edits: [] };
for (const [extension, edit] of edits) {
for (const [, edit] of edits) {
const { edits } = typeConverter.WorkspaceEdit.from(edit, {
getTextDocumentVersion: uri => this._extHostDocumentsAndEditors.getDocument(uri)?.version,
getNotebookDocumentVersion: () => undefined,
}, isProposedApiEnabled(extension, 'snippetWorkspaceEdit'));
});
dto.edits = dto.edits.concat(edits);
}
return { edit: dto, extensionNames: Array.from(extensionNames) };
Expand Down
8 changes: 4 additions & 4 deletions src/vs/workbench/api/common/extHostLanguageFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ class CodeActionAdapter {
title: candidate.title,
command: candidate.command && this._commands.toInternal(candidate.command, disposables),
diagnostics: candidate.diagnostics && candidate.diagnostics.map(typeConvert.Diagnostic.from),
edit: candidate.edit && typeConvert.WorkspaceEdit.from(candidate.edit, undefined, isProposedApiEnabled(this._extension, 'snippetWorkspaceEdit')),
edit: candidate.edit && typeConvert.WorkspaceEdit.from(candidate.edit, undefined),
kind: candidate.kind && candidate.kind.value,
isPreferred: candidate.isPreferred,
disabled: candidate.disabled?.reason
Expand All @@ -467,7 +467,7 @@ class CodeActionAdapter {
}
const resolvedItem = (await this._provider.resolveCodeAction(item, token)) ?? item;
return resolvedItem?.edit
? typeConvert.WorkspaceEdit.from(resolvedItem.edit, undefined, isProposedApiEnabled(this._extension, 'snippetWorkspaceEdit'))
? typeConvert.WorkspaceEdit.from(resolvedItem.edit, undefined)
: undefined;
}

Expand Down Expand Up @@ -522,7 +522,7 @@ class DocumentPasteEditProvider {

return {
insertText: typeof edit.insertText === 'string' ? edit.insertText : { snippet: edit.insertText.value },
additionalEdit: edit.additionalEdit ? typeConvert.WorkspaceEdit.from(edit.additionalEdit, undefined, true) : undefined,
additionalEdit: edit.additionalEdit ? typeConvert.WorkspaceEdit.from(edit.additionalEdit, undefined) : undefined,
};
}
}
Expand Down Expand Up @@ -1804,7 +1804,7 @@ class DocumentOnDropEditAdapter {
}
return {
insertText: typeof edit.insertText === 'string' ? edit.insertText : { snippet: edit.insertText.value },
additionalEdit: edit.additionalEdit ? typeConvert.WorkspaceEdit.from(edit.additionalEdit, undefined, true) : undefined,
additionalEdit: edit.additionalEdit ? typeConvert.WorkspaceEdit.from(edit.additionalEdit, undefined) : undefined,
};
}
}
Expand Down
7 changes: 1 addition & 6 deletions src/vs/workbench/api/common/extHostTypeConverters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ export namespace WorkspaceEdit {
getNotebookDocumentVersion(uri: URI): number | undefined;
}

export function from(value: vscode.WorkspaceEdit, versionInfo?: IVersionInformationProvider, allowSnippetTextEdit?: boolean): extHostProtocol.IWorkspaceEditDto {
export function from(value: vscode.WorkspaceEdit, versionInfo?: IVersionInformationProvider): extHostProtocol.IWorkspaceEditDto {
const result: extHostProtocol.IWorkspaceEditDto = {
edits: []
};
Expand Down Expand Up @@ -605,11 +605,6 @@ export namespace WorkspaceEdit {
metadata: entry.metadata
});
} else if (entry._type === types.FileEditType.Snippet) {
// snippet text edits
if (!allowSnippetTextEdit) {
console.warn(`DROPPING snippet text edit because proposal IS NOT ENABLED`, entry);
continue;
}
result.edits.push(<languages.IWorkspaceTextEdit>{
resource: entry.uri,
textEdit: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export const allApiProposals = Object.freeze({
scmActionButton: 'https://github.com/raw/microsoft/vscode/main/src/vscode-dts/vscode.proposed.scmActionButton.d.ts',
scmSelectedProvider: 'https://github.com/raw/microsoft/vscode/main/src/vscode-dts/vscode.proposed.scmSelectedProvider.d.ts',
scmValidation: 'https://github.com/raw/microsoft/vscode/main/src/vscode-dts/vscode.proposed.scmValidation.d.ts',
snippetWorkspaceEdit: 'https://github.com/raw/microsoft/vscode/main/src/vscode-dts/vscode.proposed.snippetWorkspaceEdit.d.ts',
tabInputTextMerge: 'https://github.com/raw/microsoft/vscode/main/src/vscode-dts/vscode.proposed.tabInputTextMerge.d.ts',
taskPresentationGroup: 'https://github.com/raw/microsoft/vscode/main/src/vscode-dts/vscode.proposed.taskPresentationGroup.d.ts',
telemetry: 'https://github.com/raw/microsoft/vscode/main/src/vscode-dts/vscode.proposed.telemetry.d.ts',
Expand Down
76 changes: 74 additions & 2 deletions src/vscode-dts/vscode.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3437,6 +3437,54 @@ declare module 'vscode' {
constructor(range: Range, newText: string);
}

/**
* A snippet edit represents an interactive edit that is performed by
* the editor.
*
* *Note* that a snippet edit can always be performed as a normal {@link TextEdit text edit}.
* This will happen when no matching editor is open or when a {@link WorkspaceEdit workspace edit}
* contains snippet edits for multiple files. In that case only those that match the active editor
* will be performed as snippet edits and the others as normal text edits.
*/
export class SnippetTextEdit {

/**
* Utility to create a replace snippet edit.
*
* @param range A range.
* @param snippet A snippet string.
* @return A new snippet edit object.
*/
static replace(range: Range, snippet: SnippetString): SnippetTextEdit;

/**
* Utility to create an insert snippet edit.
*
* @param position A position, will become an empty range.
* @param snippet A snippet string.
* @return A new snippet edit object.
*/
static insert(position: Position, snippet: SnippetString): SnippetTextEdit;

/**
* The range this edit applies to.
*/
range: Range;

/**
* The {@link SnippetString snippet} this edit will perform.
*/
snippet: SnippetString;

/**
* Create a new snippet edit.
*
* @param range A range.
* @param snippet A snippet string.
*/
constructor(range: Range, snippet: SnippetString);
}

/**
* A notebook edit represents edits that should be applied to the contents of a notebook.
*/
Expand Down Expand Up @@ -3582,12 +3630,36 @@ declare module 'vscode' {
has(uri: Uri): boolean;

/**
* Set (and replace) text edits for a resource.
* Set (and replace) notebook edits for a resource.
*
* @param uri A resource identifier.
* @param edits An array of edits.
*/
set(uri: Uri, edits: NotebookEdit[]): void;

/**
* Set (and replace) notebook edits with metadata for a resource.
*
* @param uri A resource identifier.
* @param edits An array of edits.
*/
set(uri: Uri, edits: [NotebookEdit, WorkspaceEditEntryMetadata][]): void;

/**
* Set (and replace) text edits or snippet edits for a resource.
*
* @param uri A resource identifier.
* @param edits An array of edits.
*/
set(uri: Uri, edits: (TextEdit | SnippetTextEdit)[]): void;

/**
* Set (and replace) text edits or snippet edits with metadata for a resource.
*
* @param uri A resource identifier.
* @param edits An array of edits.
*/
set(uri: Uri, edits: TextEdit[] | NotebookEdit[]): void;
set(uri: Uri, edits: [TextEdit | SnippetTextEdit, WorkspaceEditEntryMetadata][]): void;

/**
* Get the text edits for a resource.
Expand Down
85 changes: 0 additions & 85 deletions src/vscode-dts/vscode.proposed.snippetWorkspaceEdit.d.ts

This file was deleted.