Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 7eaa6da

Browse files
greenkeeper[bot]felixfbecker
authored andcommitted
refactor: update to fast-json-patch v2
1 parent 18d39cb commit 7eaa6da

File tree

7 files changed

+112
-112
lines changed

7 files changed

+112
-112
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"chai-as-promised": "^7.0.0",
4141
"chalk": "^1.1.3",
4242
"commander": "^2.9.0",
43-
"fast-json-patch": "^1.2.2",
43+
"fast-json-patch": "^2.0.2",
4444
"glob": "^7.1.1",
4545
"iterare": "^0.0.8",
4646
"lodash": "^4.17.4",

src/connection.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Observable, Subscription, Symbol } from '@reactivex/rxjs';
22
import { EventEmitter } from 'events';
3-
import jsonpatch from 'fast-json-patch';
3+
import { applyReducer, Operation } from 'fast-json-patch';
44
import { camelCase, omit } from 'lodash';
55
import { FORMAT_TEXT_MAP, Span, Tracer } from 'opentracing';
66
import { inspect } from 'util';
@@ -238,7 +238,7 @@ export function registerLanguageHandler(messageEmitter: MessageEmitter, messageW
238238
return;
239239
}
240240
// Call handler method with params and span
241-
let observable: Observable<jsonpatch.Operation>;
241+
let observable: Observable<Operation>;
242242
try {
243243
// Convert return value to Observable
244244
const returnValue = (handler as any)[method](message.params, span);
@@ -269,7 +269,7 @@ export function registerLanguageHandler(messageEmitter: MessageEmitter, messageW
269269
})
270270
// Build up final result for BC
271271
// TODO send null if client declared streaming capability
272-
.reduce<jsonpatch.Operation, any>(jsonpatch.applyReducer, null)
272+
.reduce<Operation, any>(applyReducer, null)
273273
.finally(() => {
274274
// Finish span
275275
span.finish();

src/request-type.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import jsonpatch from 'fast-json-patch';
1+
import { Operation } from 'fast-json-patch';
22
import * as vscode from 'vscode-languageserver';
33

44
export interface InitializeParams extends vscode.InitializeParams {
@@ -232,5 +232,5 @@ export interface PartialResultParams {
232232
* A JSON Patch that represents updates to the partial result as specified in RFC6902
233233
* https://tools.ietf.org/html/rfc6902
234234
*/
235-
patch: jsonpatch.Operation[];
235+
patch: Operation[];
236236
}

src/test/connection.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { Observable, Subject } from '@reactivex/rxjs';
33
import * as assert from 'assert';
44
import { EventEmitter } from 'events';
5-
import jsonpatch from 'fast-json-patch';
5+
import { Operation } from 'fast-json-patch';
66
import { Span } from 'opentracing';
77
import * as sinon from 'sinon';
88
import { PassThrough } from 'stream';
@@ -93,7 +93,7 @@ describe('connection', () => {
9393
});
9494
it('should call a handler on request and send the result of the returned Observable', async () => {
9595
const handler: TypeScriptService = Object.create(TypeScriptService.prototype);
96-
const hoverStub = sinon.stub(handler, 'textDocumentHover').returns(Observable.of<jsonpatch.Operation>(
96+
const hoverStub = sinon.stub(handler, 'textDocumentHover').returns(Observable.of<Operation>(
9797
{ op: 'add', path: '', value: [] },
9898
{ op: 'add', path: '/-', value: 123 }
9999
));

src/test/typescript-service-helpers.ts

Lines changed: 61 additions & 61 deletions
Large diffs are not rendered by default.

src/typescript-service.ts

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Observable } from '@reactivex/rxjs';
2-
import jsonpatch from 'fast-json-patch';
2+
import { Operation } from 'fast-json-patch';
33
import iterate from 'iterare';
44
import { toPairs } from 'lodash';
55
import { Span } from 'opentracing';
@@ -118,7 +118,7 @@ export class TypeScriptService {
118118
/**
119119
* Cached response for empty workspace/symbol query
120120
*/
121-
private emptyQueryWorkspaceSymbols: Observable<jsonpatch.Operation>;
121+
private emptyQueryWorkspaceSymbols: Observable<Operation>;
122122

123123
private traceModuleResolution: boolean;
124124

@@ -196,7 +196,7 @@ export class TypeScriptService {
196196
*
197197
* @return Observable of JSON Patches that build an `InitializeResult`
198198
*/
199-
initialize(params: InitializeParams, span = new Span()): Observable<jsonpatch.Operation> {
199+
initialize(params: InitializeParams, span = new Span()): Observable<Operation> {
200200
if (params.rootUri || params.rootPath) {
201201
this.root = params.rootPath || uri2path(params.rootUri!);
202202
this.rootUri = params.rootUri || path2uri(params.rootPath!);
@@ -268,7 +268,7 @@ export class TypeScriptService {
268268
op: 'add',
269269
path: '',
270270
value: result
271-
} as jsonpatch.Operation);
271+
} as Operation);
272272
}
273273

274274
/**
@@ -289,10 +289,10 @@ export class TypeScriptService {
289289
*
290290
* @return Observable of JSON Patches that build a `null` result
291291
*/
292-
shutdown(params = {}, span = new Span()): Observable<jsonpatch.Operation> {
292+
shutdown(params = {}, span = new Span()): Observable<Operation> {
293293
this.projectManager.dispose();
294294
this.packageManager.dispose();
295-
return Observable.of({ op: 'add', path: '', value: null } as jsonpatch.Operation);
295+
return Observable.of({ op: 'add', path: '', value: null } as Operation);
296296
}
297297

298298
/**
@@ -310,9 +310,9 @@ export class TypeScriptService {
310310
* @return Observable of JSON Patches that build a `Location[]` result
311311
*/
312312

313-
textDocumentDefinition(params: TextDocumentPositionParams, span = new Span()): Observable<jsonpatch.Operation> {
313+
textDocumentDefinition(params: TextDocumentPositionParams, span = new Span()): Observable<Operation> {
314314
return this._getDefinitionLocations(params, span)
315-
.map((location: Location): jsonpatch.Operation => ({ op: 'add', path: '/-', value: location }))
315+
.map((location: Location): Operation => ({ op: 'add', path: '/-', value: location }))
316316
.startWith({ op: 'add', path: '', value: [] });
317317
}
318318

@@ -370,9 +370,9 @@ export class TypeScriptService {
370370
* @return Observable of JSON Patches that build a `SymbolLocationInformation[]` result
371371
*/
372372

373-
textDocumentXdefinition(params: TextDocumentPositionParams, span = new Span()): Observable<jsonpatch.Operation> {
373+
textDocumentXdefinition(params: TextDocumentPositionParams, span = new Span()): Observable<Operation> {
374374
return this._getSymbolLocationInformations(params, span)
375-
.map(symbol => ({ op: 'add', path: '/-', value: symbol } as jsonpatch.Operation))
375+
.map(symbol => ({ op: 'add', path: '/-', value: symbol } as Operation))
376376
.startWith({ op: 'add', path: '', value: [] });
377377
}
378378

@@ -494,9 +494,9 @@ export class TypeScriptService {
494494
*
495495
* @return Observable of JSON Patches that build a `Hover` result
496496
*/
497-
textDocumentHover(params: TextDocumentPositionParams, span = new Span()): Observable<jsonpatch.Operation> {
497+
textDocumentHover(params: TextDocumentPositionParams, span = new Span()): Observable<Operation> {
498498
return this._getHover(params, span)
499-
.map(hover => ({ op: 'add', path: '', value: hover }) as jsonpatch.Operation);
499+
.map(hover => ({ op: 'add', path: '', value: hover }) as Operation);
500500
}
501501

502502
/**
@@ -572,7 +572,7 @@ export class TypeScriptService {
572572
*
573573
* @return Observable of JSON Patches that build a `Location[]` result
574574
*/
575-
textDocumentReferences(params: ReferenceParams, span = new Span()): Observable<jsonpatch.Operation> {
575+
textDocumentReferences(params: ReferenceParams, span = new Span()): Observable<Operation> {
576576
const uri = normalizeUri(params.textDocument.uri);
577577

578578
// Ensure all files were fetched to collect all references
@@ -621,7 +621,7 @@ export class TypeScriptService {
621621
};
622622
});
623623
}))
624-
.map((location: Location): jsonpatch.Operation => ({ op: 'add', path: '/-', value: location }))
624+
.map((location: Location): Operation => ({ op: 'add', path: '/-', value: location }))
625625
// Initialize with array
626626
.startWith({ op: 'add', path: '', value: [] });
627627
}
@@ -633,7 +633,7 @@ export class TypeScriptService {
633633
*
634634
* @return Observable of JSON Patches that build a `SymbolInformation[]` result
635635
*/
636-
workspaceSymbol(params: WorkspaceSymbolParams, span = new Span()): Observable<jsonpatch.Operation> {
636+
workspaceSymbol(params: WorkspaceSymbolParams, span = new Span()): Observable<Operation> {
637637

638638
// Return cached result for empty query, if available
639639
if (!params.query && !params.symbol && this.emptyQueryWorkspaceSymbols) {
@@ -705,10 +705,10 @@ export class TypeScriptService {
705705
const index = scores.findIndex(s => s < score);
706706
if (index === -1) {
707707
scores.push(score);
708-
return { op: 'add', path: '/-', value: symbol } as jsonpatch.Operation;
708+
return { op: 'add', path: '/-', value: symbol } as Operation;
709709
}
710710
scores.splice(index, 0, score);
711-
return { op: 'add', path: '/' + index, value: symbol } as jsonpatch.Operation;
711+
return { op: 'add', path: '/' + index, value: symbol } as Operation;
712712
})
713713
.startWith({ op: 'add', path: '', value: [] });
714714

@@ -725,7 +725,7 @@ export class TypeScriptService {
725725
*
726726
* @return Observable of JSON Patches that build a `SymbolInformation[]` result
727727
*/
728-
textDocumentDocumentSymbol(params: DocumentSymbolParams, span = new Span()): Observable<jsonpatch.Operation> {
728+
textDocumentDocumentSymbol(params: DocumentSymbolParams, span = new Span()): Observable<Operation> {
729729
const uri = normalizeUri(params.textDocument.uri);
730730

731731
// Ensure files needed to resolve symbols are fetched
@@ -745,8 +745,8 @@ export class TypeScriptService {
745745
.filter(({ tree, parent }) => navigationTreeIsSymbol(tree))
746746
.map(({ tree, parent }) => navigationTreeToSymbolInformation(tree, parent, sourceFile, this.root));
747747
})
748-
.map(symbol => ({ op: 'add', path: '/-', value: symbol }) as jsonpatch.Operation)
749-
.startWith({ op: 'add', path: '', value: [] } as jsonpatch.Operation);
748+
.map(symbol => ({ op: 'add', path: '/-', value: symbol }) as Operation)
749+
.startWith({ op: 'add', path: '', value: [] } as Operation);
750750
}
751751

752752
/**
@@ -755,7 +755,7 @@ export class TypeScriptService {
755755
*
756756
* @return Observable of JSON Patches that build a `ReferenceInformation[]` result
757757
*/
758-
workspaceXreferences(params: WorkspaceReferenceParams, span = new Span()): Observable<jsonpatch.Operation> {
758+
workspaceXreferences(params: WorkspaceReferenceParams, span = new Span()): Observable<Operation> {
759759
const queryWithoutPackage = omit(params.query, 'package');
760760
const minScore = Math.min(4.75, getPropertyCount(queryWithoutPackage));
761761
return this.isDefinitelyTyped
@@ -844,7 +844,7 @@ export class TypeScriptService {
844844
})
845845
);
846846
})
847-
.map((reference): jsonpatch.Operation => ({ op: 'add', path: '/-', value: reference }))
847+
.map((reference): Operation => ({ op: 'add', path: '/-', value: reference }))
848848
.startWith({ op: 'add', path: '', value: [] });
849849
}
850850

@@ -861,7 +861,7 @@ export class TypeScriptService {
861861
*
862862
* @return Observable of JSON Patches that build a `PackageInformation[]` result
863863
*/
864-
workspaceXpackages(params = {}, span = new Span()): Observable<jsonpatch.Operation> {
864+
workspaceXpackages(params = {}, span = new Span()): Observable<Operation> {
865865
return this.isDefinitelyTyped
866866
.mergeMap((isDefinitelyTyped: boolean): Observable<PackageInformation> => {
867867
// In DefinitelyTyped, report all @types/ packages
@@ -920,7 +920,7 @@ export class TypeScriptService {
920920
}));
921921
});
922922
})
923-
.map((packageInfo): jsonpatch.Operation => ({ op: 'add', path: '/-', value: packageInfo }))
923+
.map((packageInfo): Operation => ({ op: 'add', path: '/-', value: packageInfo }))
924924
.startWith({ op: 'add', path: '', value: [] });
925925
}
926926

@@ -930,7 +930,7 @@ export class TypeScriptService {
930930
*
931931
* @return Observable of JSON Patches that build a `DependencyReference[]` result
932932
*/
933-
workspaceXdependencies(params = {}, span = new Span()): Observable<jsonpatch.Operation> {
933+
workspaceXdependencies(params = {}, span = new Span()): Observable<Operation> {
934934
// Ensure package.json files
935935
return this.projectManager.ensureModuleStructure()
936936
// Iterate all files
@@ -955,7 +955,7 @@ export class TypeScriptService {
955955
}
956956
}))
957957
)
958-
.map((dependency): jsonpatch.Operation => ({ op: 'add', path: '/-', value: dependency }))
958+
.map((dependency): Operation => ({ op: 'add', path: '/-', value: dependency }))
959959
.startWith({ op: 'add', path: '', value: [] });
960960
}
961961

@@ -974,7 +974,7 @@ export class TypeScriptService {
974974
*
975975
* @return Observable of JSON Patches that build a `CompletionList` result
976976
*/
977-
textDocumentCompletion(params: TextDocumentPositionParams, span = new Span()): Observable<jsonpatch.Operation> {
977+
textDocumentCompletion(params: TextDocumentPositionParams, span = new Span()): Observable<Operation> {
978978
const uri = normalizeUri(params.textDocument.uri);
979979

980980
// Ensure files needed to suggest completions are fetched
@@ -1014,11 +1014,11 @@ export class TypeScriptService {
10141014
item.documentation = ts.displayPartsToString(details.documentation);
10151015
item.detail = ts.displayPartsToString(details.displayParts);
10161016
}
1017-
return { op: 'add', path: '/items/-', value: item } as jsonpatch.Operation;
1017+
return { op: 'add', path: '/items/-', value: item } as Operation;
10181018
})
1019-
.startWith({ op: 'add', path: '/isIncomplete', value: false } as jsonpatch.Operation);
1019+
.startWith({ op: 'add', path: '/isIncomplete', value: false } as Operation);
10201020
})
1021-
.startWith({ op: 'add', path: '', value: { isIncomplete: true, items: [] } as CompletionList } as jsonpatch.Operation);
1021+
.startWith({ op: 'add', path: '', value: { isIncomplete: true, items: [] } as CompletionList } as Operation);
10221022
}
10231023

10241024
/**
@@ -1027,7 +1027,7 @@ export class TypeScriptService {
10271027
*
10281028
* @return Observable of JSON Patches that build a `SignatureHelp` result
10291029
*/
1030-
textDocumentSignatureHelp(params: TextDocumentPositionParams, span = new Span()): Observable<jsonpatch.Operation> {
1030+
textDocumentSignatureHelp(params: TextDocumentPositionParams, span = new Span()): Observable<Operation> {
10311031
const uri = normalizeUri(params.textDocument.uri);
10321032

10331033
// Ensure files needed to resolve signature are fetched
@@ -1071,7 +1071,7 @@ export class TypeScriptService {
10711071
activeParameter: signatures.argumentIndex
10721072
};
10731073
})
1074-
.map(signatureHelp => ({ op: 'add', path: '', value: signatureHelp }) as jsonpatch.Operation);
1074+
.map(signatureHelp => ({ op: 'add', path: '', value: signatureHelp }) as Operation);
10751075
}
10761076

10771077
/**
@@ -1081,7 +1081,7 @@ export class TypeScriptService {
10811081
*
10821082
* @return Observable of JSON Patches that build a `Command[]` result
10831083
*/
1084-
textDocumentCodeAction(params: CodeActionParams, span = new Span()): Observable<jsonpatch.Operation> {
1084+
textDocumentCodeAction(params: CodeActionParams, span = new Span()): Observable<Operation> {
10851085
const uri = normalizeUri(params.textDocument.uri);
10861086
return this.projectManager.ensureReferencedFiles(uri, undefined, undefined, span)
10871087
.toArray()
@@ -1108,7 +1108,7 @@ export class TypeScriptService {
11081108

11091109
return configuration.getService().getCodeFixesAtPosition(filePath, start, end, errorCodes, this.settings.format || {}) || [];
11101110
})
1111-
.map((action: ts.CodeAction): jsonpatch.Operation => ({
1111+
.map((action: ts.CodeAction): Operation => ({
11121112
op: 'add',
11131113
path: '/-',
11141114
value: {
@@ -1117,7 +1117,7 @@ export class TypeScriptService {
11171117
arguments: action.changes
11181118
} as Command
11191119
}))
1120-
.startWith({ op: 'add', path: '', value: [] } as jsonpatch.Operation);
1120+
.startWith({ op: 'add', path: '', value: [] } as Operation);
11211121
}
11221122

11231123
/**
@@ -1126,7 +1126,7 @@ export class TypeScriptService {
11261126
* applies the changes to the workspace using the request workspace/applyEdit which is sent from
11271127
* the server to the client.
11281128
*/
1129-
workspaceExecuteCommand(params: ExecuteCommandParams, span = new Span()): Observable<jsonpatch.Operation> {
1129+
workspaceExecuteCommand(params: ExecuteCommandParams, span = new Span()): Observable<Operation> {
11301130
switch (params.command) {
11311131
case 'codeFix':
11321132
if (!params.arguments || params.arguments.length < 1) {
@@ -1143,7 +1143,7 @@ export class TypeScriptService {
11431143
*
11441144
* @return Observable of JSON Patches for `null` result
11451145
*/
1146-
executeCodeFixCommand(fileTextChanges: ts.FileTextChanges[], span = new Span()): Observable<jsonpatch.Operation> {
1146+
executeCodeFixCommand(fileTextChanges: ts.FileTextChanges[], span = new Span()): Observable<Operation> {
11471147
if (fileTextChanges.length === 0) {
11481148
return Observable.throw(new Error('No changes supplied for code fix command'));
11491149
}
@@ -1171,15 +1171,15 @@ export class TypeScriptService {
11711171

11721172
return this.client.workspaceApplyEdit({ edit: { changes }}, span);
11731173
}))
1174-
.map(() => ({ op: 'add', path: '', value: null }) as jsonpatch.Operation);
1174+
.map(() => ({ op: 'add', path: '', value: null }) as Operation);
11751175
}
11761176

11771177
/**
11781178
* The rename request is sent from the client to the server to perform a workspace-wide rename of a symbol.
11791179
*
11801180
* @return Observable of JSON Patches that build a `WorkspaceEdit` result
11811181
*/
1182-
textDocumentRename(params: RenameParams, span = new Span()): Observable<jsonpatch.Operation> {
1182+
textDocumentRename(params: RenameParams, span = new Span()): Observable<Operation> {
11831183
const uri = normalizeUri(params.textDocument.uri);
11841184
const editUris = new Set<string>();
11851185
return this.projectManager.ensureOwnFiles(span)
@@ -1217,7 +1217,7 @@ export class TypeScriptService {
12171217
return [editUri, edit];
12181218
});
12191219
}))
1220-
.map(([uri, edit]): jsonpatch.Operation => {
1220+
.map(([uri, edit]): Operation => {
12211221
// if file has no edit yet, initialize array
12221222
if (!editUris.has(uri)) {
12231223
editUris.add(uri);
@@ -1226,7 +1226,7 @@ export class TypeScriptService {
12261226
// else append to array
12271227
return { op: 'add', path: JSONPTR`/changes/${uri}/-`, value: edit };
12281228
})
1229-
.startWith({ op: 'add', path: '', value: { changes: {} } as WorkspaceEdit } as jsonpatch.Operation);
1229+
.startWith({ op: 'add', path: '', value: { changes: {} } as WorkspaceEdit } as Operation);
12301230
}
12311231

12321232
/**

0 commit comments

Comments
 (0)