Skip to content

Commit

Permalink
move SnippetTextEdit into vscode-dts
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Sep 8, 2022
1 parent b8afe8d commit 20527c0
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 98 deletions.
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 @@ -53,7 +53,6 @@ export const allApiProposals = Object.freeze({
scmActionButton: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.scmActionButton.d.ts',
scmSelectedProvider: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.scmSelectedProvider.d.ts',
scmValidation: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.scmValidation.d.ts',
snippetWorkspaceEdit: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.snippetWorkspaceEdit.d.ts',
tabInputTextMerge: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.tabInputTextMerge.d.ts',
taskPresentationGroup: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.taskPresentationGroup.d.ts',
telemetry: 'https://raw.githubusercontent.com/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 @@ -3426,6 +3426,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 an 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 @@ -3571,12 +3619,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.

0 comments on commit 20527c0

Please sign in to comment.