mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
Use the updateOpen TS api to sync multiple changes in a single file
Fixes #69492
This commit is contained in:
parent
013501950e
commit
2a2f817990
|
@ -3,7 +3,7 @@
|
|||
"version": "0.0.1",
|
||||
"description": "Dependencies shared by all extensions",
|
||||
"dependencies": {
|
||||
"typescript": "3.3.3"
|
||||
"typescript": "3.4.0-dev.20190306"
|
||||
},
|
||||
"scripts": {
|
||||
"postinstall": "node ./postinstall"
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
# yarn lockfile v1
|
||||
|
||||
|
||||
typescript@3.3.3:
|
||||
version "3.3.3"
|
||||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.3.3.tgz#f1657fc7daa27e1a8930758ace9ae8da31403221"
|
||||
integrity sha512-Y21Xqe54TBVp+VDSNbuDYdGw0BpoR/Q6wo/+35M8PAU0vipahnyduJWirxxdxjsAkS7hue53x2zp8gz7F05u0A==
|
||||
typescript@3.4.0-dev.20190306:
|
||||
version "3.4.0-dev.20190306"
|
||||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.4.0-dev.20190306.tgz#6431063ef07e642aac44504a7ea1b59c38f7d935"
|
||||
integrity sha512-fnIi34ml8qtAqrT27zWPV5eBX9eAMVLqHCl/MZ4qHzLNWj98vp70Dde8ObNlOmuGIjumGQDHFgk7fowXJaq9gw==
|
||||
|
|
Loading…
Reference in a new issue