Skip to content

Commit 3868fb5

Browse files
author
steveluc
committed
Removed deleteLen from change request; added endLine, endCol that mark
the end of the deleted Range (inclusive). DeleteLen was not always accurate because editors normalize \r\n to \n in some cases, affecting the length of ranges. In Diagnostic response items, changed len field to end to address the same range length issue. Flattened MessageDiagnosticChains in diagnostic message text, since clients expect string there. Renamed ts.server.protocol to simply protocol in session.ts and client.ts since module name prefix is clear. Based on protocol feedback: Changed LineCol to Location. Changed CodeLocation interface name prefix to FileLocation. Changed DiagEvent to DiagnosticEvent. Removed anonymous types.
1 parent cadd57c commit 3868fb5

3 files changed

Lines changed: 153 additions & 158 deletions

File tree

src/server/client.ts

Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,19 @@ module ts.server {
4747
return lineMap;
4848
}
4949

50-
private lineColToPosition(fileName: string, lineCol: ts.server.protocol.LineCol): number {
50+
private lineColToPosition(fileName: string, lineCol: protocol.Location): number {
5151
return ts.computePositionFromLineAndCharacter(this.getLineMap(fileName), lineCol.line, lineCol.col);
5252
}
5353

54-
private positionToOneBasedLineCol(fileName: string, position: number): ts.server.protocol.LineCol {
54+
private positionToOneBasedLineCol(fileName: string, position: number): protocol.Location {
5555
var lineCol = ts.computeLineAndCharacterOfPosition(this.getLineMap(fileName), position);
5656
return {
5757
line: lineCol.line,
5858
col: lineCol.character
5959
};
6060
}
6161

62-
private convertCodeEditsToTextChange(fileName: string, codeEdit: ts.server.protocol.CodeEdit): ts.TextChange {
62+
private convertCodeEditsToTextChange(fileName: string, codeEdit: protocol.CodeEdit): ts.TextChange {
6363
var start = this.lineColToPosition(fileName, codeEdit.start);
6464
var end = this.lineColToPosition(fileName, codeEdit.end);
6565

@@ -69,8 +69,8 @@ module ts.server {
6969
};
7070
}
7171

72-
private processRequest<T extends ts.server.protocol.Request>(command: string, arguments?: any): T {
73-
var request: ts.server.protocol.Request = {
72+
private processRequest<T extends protocol.Request>(command: string, arguments?: any): T {
73+
var request: protocol.Request = {
7474
seq: this.sequence++,
7575
type: "request",
7676
command: command,
@@ -82,7 +82,7 @@ module ts.server {
8282
return <T>request;
8383
}
8484

85-
private processResponse<T extends ts.server.protocol.Response>(request: ts.server.protocol.Request): T {
85+
private processResponse<T extends protocol.Response>(request: protocol.Request): T {
8686
var lastMessage = this.messages.shift();
8787
Debug.assert(!!lastMessage, "Did not recieve any responses.");
8888

@@ -122,12 +122,12 @@ module ts.server {
122122
}
123123

124124
openFile(fileName: string): void {
125-
var args: ts.server.protocol.FileRequestArgs = { file: fileName };
125+
var args: protocol.FileRequestArgs = { file: fileName };
126126
this.processRequest(CommandNames.Open, args);
127127
}
128128

129129
closeFile(fileName: string): void {
130-
var args: ts.server.protocol.FileRequestArgs = { file: fileName };
130+
var args: protocol.FileRequestArgs = { file: fileName };
131131
this.processRequest(CommandNames.Close, args);
132132
}
133133

@@ -136,12 +136,14 @@ module ts.server {
136136
this.lineMaps[fileName] = undefined;
137137

138138
var lineCol = this.positionToOneBasedLineCol(fileName, start);
139-
var args: ts.server.protocol.ChangeRequestArgs = {
139+
var endLineCol = this.positionToOneBasedLineCol(fileName, end);
140+
141+
var args: protocol.ChangeRequestArgs = {
140142
file: fileName,
141143
line: lineCol.line,
142144
col: lineCol.col,
143-
insertLen: end - start,
144-
deleteLen: end - start,
145+
endLine: endLineCol.line,
146+
endCol: endLineCol.col,
145147
insertString: newText
146148
};
147149

@@ -150,14 +152,14 @@ module ts.server {
150152

151153
getQuickInfoAtPosition(fileName: string, position: number): QuickInfo {
152154
var lineCol = this.positionToOneBasedLineCol(fileName, position);
153-
var args: ts.server.protocol.CodeLocationRequestArgs = {
155+
var args: protocol.FileLocationRequestArgs = {
154156
file: fileName,
155157
line: lineCol.line,
156158
col: lineCol.col
157159
};
158160

159-
var request = this.processRequest<ts.server.protocol.QuickInfoRequest>(CommandNames.Quickinfo, args);
160-
var response = this.processResponse<ts.server.protocol.QuickInfoResponse>(request);
161+
var request = this.processRequest<protocol.QuickInfoRequest>(CommandNames.Quickinfo, args);
162+
var response = this.processResponse<protocol.QuickInfoResponse>(request);
161163

162164
var start = this.lineColToPosition(fileName, response.body.start);
163165
var end = this.lineColToPosition(fileName, response.body.end);
@@ -173,15 +175,15 @@ module ts.server {
173175

174176
getCompletionsAtPosition(fileName: string, position: number): CompletionInfo {
175177
var lineCol = this.positionToOneBasedLineCol(fileName, position);
176-
var args: ts.server.protocol.CompletionsRequestArgs = {
178+
var args: protocol.CompletionsRequestArgs = {
177179
file: fileName,
178180
line: lineCol.line,
179181
col: lineCol.col,
180182
prefix: undefined
181183
};
182184

183-
var request = this.processRequest<ts.server.protocol.CompletionsRequest>(CommandNames.Completions, args);
184-
var response = this.processResponse<ts.server.protocol.CompletionsResponse>(request);
185+
var request = this.processRequest<protocol.CompletionsRequest>(CommandNames.Completions, args);
186+
var response = this.processResponse<protocol.CompletionsResponse>(request);
185187

186188
return this.lastCompletionEntry = {
187189
isMemberCompletion: false,
@@ -207,13 +209,13 @@ module ts.server {
207209
}
208210

209211
getNavigateToItems(searchTerm: string): NavigateToItem[] {
210-
var args: ts.server.protocol.NavtoRequestArgs = {
212+
var args: protocol.NavtoRequestArgs = {
211213
searchTerm,
212214
file: this.host.getScriptFileNames()[0]
213215
};
214216

215-
var request = this.processRequest<ts.server.protocol.NavtoRequest>(CommandNames.Navto, args);
216-
var response = this.processResponse<ts.server.protocol.NavtoResponse>(request);
217+
var request = this.processRequest<protocol.NavtoRequest>(CommandNames.Navto, args);
218+
var response = this.processResponse<protocol.NavtoResponse>(request);
217219

218220
return response.body.map(entry => {
219221
var fileName = entry.file;
@@ -236,7 +238,7 @@ module ts.server {
236238
getFormattingEditsForRange(fileName: string, start: number, end: number, options: ts.FormatCodeOptions): ts.TextChange[] {
237239
var startLineCol = this.positionToOneBasedLineCol(fileName, start);
238240
var endLineCol = this.positionToOneBasedLineCol(fileName, end);
239-
var args: ts.server.protocol.FormatRequestArgs = {
241+
var args: protocol.FormatRequestArgs = {
240242
file: fileName,
241243
line: startLineCol.line,
242244
col: startLineCol.col,
@@ -245,8 +247,8 @@ module ts.server {
245247
};
246248

247249
// TODO: handle FormatCodeOptions
248-
var request = this.processRequest<ts.server.protocol.FormatRequest>(CommandNames.Format, args);
249-
var response = this.processResponse<ts.server.protocol.FormatResponse>(request);
250+
var request = this.processRequest<protocol.FormatRequest>(CommandNames.Format, args);
251+
var response = this.processResponse<protocol.FormatResponse>(request);
250252

251253
return response.body.map(entry=> this.convertCodeEditsToTextChange(fileName, entry));
252254
}
@@ -257,30 +259,30 @@ module ts.server {
257259

258260
getFormattingEditsAfterKeystroke(fileName: string, position: number, key: string, options: FormatCodeOptions): ts.TextChange[] {
259261
var lineCol = this.positionToOneBasedLineCol(fileName, position);
260-
var args: ts.server.protocol.FormatOnKeyRequestArgs = {
262+
var args: protocol.FormatOnKeyRequestArgs = {
261263
file: fileName,
262264
line: lineCol.line,
263265
col: lineCol.col,
264266
key: key
265267
};
266268

267269
// TODO: handle FormatCodeOptions
268-
var request = this.processRequest<ts.server.protocol.FormatOnKeyRequest>(CommandNames.Formatonkey, args);
269-
var response = this.processResponse<ts.server.protocol.FormatResponse>(request);
270+
var request = this.processRequest<protocol.FormatOnKeyRequest>(CommandNames.Formatonkey, args);
271+
var response = this.processResponse<protocol.FormatResponse>(request);
270272

271273
return response.body.map(entry=> this.convertCodeEditsToTextChange(fileName, entry));
272274
}
273275

274276
getDefinitionAtPosition(fileName: string, position: number): DefinitionInfo[] {
275277
var lineCol = this.positionToOneBasedLineCol(fileName, position);
276-
var args: ts.server.protocol.CodeLocationRequestArgs = {
278+
var args: protocol.FileLocationRequestArgs = {
277279
file: fileName,
278280
line: lineCol.line,
279281
col: lineCol.col,
280282
};
281283

282-
var request = this.processRequest<ts.server.protocol.DefinitionRequest>(CommandNames.Definition, args);
283-
var response = this.processResponse<ts.server.protocol.DefinitionResponse>(request);
284+
var request = this.processRequest<protocol.DefinitionRequest>(CommandNames.Definition, args);
285+
var response = this.processResponse<protocol.DefinitionResponse>(request);
284286

285287
return response.body.map(entry => {
286288
var fileName = entry.file;
@@ -299,14 +301,14 @@ module ts.server {
299301

300302
getReferencesAtPosition(fileName: string, position: number): ReferenceEntry[] {
301303
var lineCol = this.positionToOneBasedLineCol(fileName, position);
302-
var args: ts.server.protocol.CodeLocationRequestArgs = {
304+
var args: protocol.FileLocationRequestArgs = {
303305
file: fileName,
304306
line: lineCol.line,
305307
col: lineCol.col,
306308
};
307309

308-
var request = this.processRequest<ts.server.protocol.ReferencesRequest>(CommandNames.References, args);
309-
var response = this.processResponse<ts.server.protocol.ReferencesResponse>(request);
310+
var request = this.processRequest<protocol.ReferencesRequest>(CommandNames.References, args);
311+
var response = this.processResponse<protocol.ReferencesResponse>(request);
310312

311313
return response.body.refs.map(entry => {
312314
var fileName = entry.file;
@@ -338,20 +340,20 @@ module ts.server {
338340

339341
getRenameInfo(fileName: string, position: number, findInStrings?: boolean, findInComments?: boolean): RenameInfo {
340342
var lineCol = this.positionToOneBasedLineCol(fileName, position);
341-
var args: ts.server.protocol.RenameRequestArgs = {
343+
var args: protocol.RenameRequestArgs = {
342344
file: fileName,
343345
line: lineCol.line,
344346
col: lineCol.col,
345347
findInStrings,
346348
findInComments
347349
};
348350

349-
var request = this.processRequest<ts.server.protocol.RenameRequest>(CommandNames.Rename, args);
350-
var response = this.processResponse<ts.server.protocol.RenameResponse>(request);
351+
var request = this.processRequest<protocol.RenameRequest>(CommandNames.Rename, args);
352+
var response = this.processResponse<protocol.RenameResponse>(request);
351353
var locations: RenameLocation[] = [];
352-
response.body.locs.map((entry: ts.server.protocol.SpanGroup) => {
354+
response.body.locs.map((entry: protocol.SpanGroup) => {
353355
var fileName = entry.file;
354-
entry.locs.map((loc: ts.server.protocol.TextSpan) => {
356+
entry.locs.map((loc: protocol.TextSpan) => {
355357
var start = this.lineColToPosition(fileName, loc.start);
356358
var end = this.lineColToPosition(fileName, loc.end);
357359
locations.push({
@@ -388,7 +390,7 @@ module ts.server {
388390
return this.lastRenameEntry.locations;
389391
}
390392

391-
decodeNavigationBarItems(items: ts.server.protocol.NavigationBarItem[], fileName: string): NavigationBarItem[] {
393+
decodeNavigationBarItems(items: protocol.NavigationBarItem[], fileName: string): NavigationBarItem[] {
392394
if (!items) {
393395
return [];
394396
}
@@ -406,12 +408,12 @@ module ts.server {
406408
}
407409

408410
getNavigationBarItems(fileName: string): NavigationBarItem[] {
409-
var args: ts.server.protocol.FileRequestArgs = {
411+
var args: protocol.FileRequestArgs = {
410412
file: fileName
411413
};
412414

413-
var request = this.processRequest<ts.server.protocol.NavBarRequest>(CommandNames.NavBar, args);
414-
var response = this.processResponse<ts.server.protocol.NavBarResponse>(request);
415+
var request = this.processRequest<protocol.NavBarRequest>(CommandNames.NavBar, args);
416+
var response = this.processResponse<protocol.NavBarResponse>(request);
415417

416418
return this.decodeNavigationBarItems(response.body, fileName);
417419
}
@@ -437,19 +439,19 @@ module ts.server {
437439
}
438440

439441
getTodoComments(fileName: string, descriptors: TodoCommentDescriptor[]): TodoComment[] {
440-
throw new Error("Not Implemented Yet.");
442+
throw new Error("Not Implemented Yet.");
441443
}
442444

443445
getBraceMatchingAtPosition(fileName: string, position: number): TextSpan[] {
444446
var lineCol = this.positionToOneBasedLineCol(fileName, position);
445-
var args: ts.server.protocol.CodeLocationRequestArgs = {
447+
var args: protocol.FileLocationRequestArgs = {
446448
file: fileName,
447449
line: lineCol.line,
448450
col: lineCol.col,
449451
};
450452

451-
var request = this.processRequest<ts.server.protocol.BraceRequest>(CommandNames.Brace, args);
452-
var response = this.processResponse<ts.server.protocol.BraceResponse>(request);
453+
var request = this.processRequest<protocol.BraceRequest>(CommandNames.Brace, args);
454+
var response = this.processResponse<protocol.BraceResponse>(request);
453455

454456
return response.body.map(entry => {
455457
var start = this.lineColToPosition(fileName, entry.start);

0 commit comments

Comments
 (0)