mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-23 03:39:23 +00:00
Use the updateOpen TS api to sync multiple changes in a single file
Fixes #69492
This commit is contained in:
@@ -108,12 +108,26 @@ class SyncedBuffer {
|
||||
console.error(`Unexpected buffer state: ${this.state}`);
|
||||
}
|
||||
|
||||
for (const { range, text } of events) {
|
||||
const args: Proto.ChangeRequestArgs = {
|
||||
insertString: text,
|
||||
...typeConverters.Range.toFormattingRequestArgs(this.filepath, range)
|
||||
if (this.client.apiVersion.gte(API.v340)) {
|
||||
const args: Proto.UpdateOpenRequestArgs = {
|
||||
changedFiles: [{
|
||||
fileName: this.filepath,
|
||||
textChanges: events.map((change): Proto.CodeEdit => ({
|
||||
newText: change.text,
|
||||
start: typeConverters.Position.toLocation(change.range.start),
|
||||
end: typeConverters.Position.toLocation(change.range.end),
|
||||
})).reverse(), // Send the edits end of document to start of document order
|
||||
}],
|
||||
};
|
||||
this.client.executeWithoutWaitingForResponse('change', args);
|
||||
this.client.executeWithoutWaitingForResponse('updateOpen', args);
|
||||
} else {
|
||||
for (const { range, text } of events) {
|
||||
const args: Proto.ChangeRequestArgs = {
|
||||
insertString: text,
|
||||
...typeConverters.Range.toFormattingRequestArgs(this.filepath, range)
|
||||
};
|
||||
this.client.executeWithoutWaitingForResponse('change', args);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,6 +110,7 @@ export interface ITypeScriptServiceClient {
|
||||
executeWithoutWaitingForResponse(command: 'open', args: Proto.OpenRequestArgs): void;
|
||||
executeWithoutWaitingForResponse(command: 'close', args: Proto.FileRequestArgs): void;
|
||||
executeWithoutWaitingForResponse(command: 'change', args: Proto.ChangeRequestArgs): void;
|
||||
executeWithoutWaitingForResponse(command: 'updateOpen', args: Proto.UpdateOpenRequestArgs): void;
|
||||
executeWithoutWaitingForResponse(command: 'compilerOptionsForInferredProjects', args: Proto.SetCompilerOptionsForInferredProjectsArgs): void;
|
||||
executeWithoutWaitingForResponse(command: 'reloadProjects', args: null): void;
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ export default class API {
|
||||
public static readonly v320 = API.fromSimpleString('3.2.0');
|
||||
public static readonly v330 = API.fromSimpleString('3.3.0');
|
||||
public static readonly v333 = API.fromSimpleString('3.3.3');
|
||||
public static readonly v340 = API.fromSimpleString('3.4.0');
|
||||
|
||||
|
||||
public static fromVersionString(versionString: string): API {
|
||||
|
||||
@@ -38,6 +38,11 @@ export namespace Position {
|
||||
export const fromLocation = (tslocation: Proto.Location): vscode.Position =>
|
||||
new vscode.Position(tslocation.line - 1, tslocation.offset - 1);
|
||||
|
||||
export const toLocation = (vsPosition: vscode.Position): Proto.Location => ({
|
||||
line: vsPosition.line + 1,
|
||||
offset: vsPosition.character + 1,
|
||||
});
|
||||
|
||||
export const toFileLocationRequestArgs = (file: string, position: vscode.Position): Proto.FileLocationRequestArgs => ({
|
||||
file,
|
||||
line: position.line + 1,
|
||||
|
||||
Reference in New Issue
Block a user