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

Commit bd4f30a

Browse files
authored
Upgrade TypeScript and modernize practices (#73)
* Upgrade TypeScript and modernize practices * chore(deps): upgrade prettier to support new ECMAScript features * fix: type errors with TypeScript 3.7
1 parent 3c279fe commit bd4f30a

File tree

8 files changed

+54
-103
lines changed

8 files changed

+54
-103
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@
6666
"mocha": "^6.0.0",
6767
"mock-require": "^3.0.3",
6868
"nyc": "^13.1.0",
69-
"prettier": "^1.16.4",
69+
"prettier": "^1.19.1",
7070
"semantic-release": "^16.0.0-beta.46",
7171
"sinon": "^7.4.1",
7272
"ts-node": "^8.0.2",
7373
"tslint": "^5.20.1",
74-
"typescript": "^3.2.2"
74+
"typescript": "^3.7.4"
7575
},
7676
"dependencies": {
7777
"@sourcegraph/vscode-ws-jsonrpc": "^0.0.3-fork",

src/connection.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,7 @@ export const webSocketTransport = ({
5858
get closed(): boolean {
5959
return socket.readyState === WebSocket.CLOSED || socket.readyState === WebSocket.CLOSING
6060
},
61-
closeEvent: fromEvent<Event>(socket, 'close').pipe(
62-
mapTo(undefined),
63-
take(1)
64-
),
61+
closeEvent: fromEvent<Event>(socket, 'close').pipe(mapTo(undefined), take(1)),
6562
sendRequest: async (type, params) => connection.sendRequest(type, params),
6663
sendNotification: async (type, params) => connection.sendNotification(type, params),
6764
setRequestHandler: (type, handler) => connection.onRequest(type, handler),

src/features/feature.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ export function scopeDocumentSelectorToRoot(
3636
.map(filter => ({
3737
...filter,
3838
// TODO filter.pattern needs to be run resolved relative to server root URI before mounting on clientRootUri
39-
pattern: new URL(filter.pattern || '**', clientRootUri).href,
39+
pattern: new URL(filter.pattern ?? '**', clientRootUri).href,
4040
}))
4141
}

src/index.ts

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export async function register({
120120
textDocument: {
121121
uri: serverTextDocumentUri.href,
122122
languageId: textDocument.languageId,
123-
text: textDocument.text || '', // TODO try to fetch contents from somewhere
123+
text: textDocument.text ?? '', // TODO try to fetch contents from somewhere
124124
version: 1,
125125
},
126126
}
@@ -209,7 +209,7 @@ export async function register({
209209
sourcegraph.workspace.openedTextDocuments.subscribe(() => {
210210
for (const appWindow of sourcegraph.app.windows) {
211211
for (const viewComponent of appWindow.visibleViewComponents) {
212-
const diagnostics = diagnosticsByUri.get(viewComponent.document.uri) || []
212+
const diagnostics = diagnosticsByUri.get(viewComponent.document.uri) ?? []
213213
viewComponent.setDecorations(
214214
decorationType,
215215
diagnostics.map(d => convertDiagnosticToDecoration(sourcegraph, d))
@@ -287,16 +287,13 @@ export async function register({
287287
let withConnection: <R>(workspaceFolder: URL, fn: (connection: LSPConnection) => Promise<R>) => Promise<R>
288288

289289
if (supportsWorkspaceFolders) {
290-
const connection = await connect(
291-
null,
292-
{
293-
processId: null,
294-
rootUri: null,
295-
capabilities: clientCapabilities,
296-
workspaceFolders: sourcegraph.workspace.roots.map(toLSPWorkspaceFolder({ clientToServerURI })),
297-
initializationOptions,
298-
}
299-
)
290+
const connection = await connect(null, {
291+
processId: null,
292+
rootUri: null,
293+
capabilities: clientCapabilities,
294+
workspaceFolders: sourcegraph.workspace.roots.map(toLSPWorkspaceFolder({ clientToServerURI })),
295+
initializationOptions,
296+
})
300297
subscriptions.add(connection)
301298
withConnection = async (workspaceFolder, fn) => {
302299
let tempWorkspaceFolder: WorkspaceFolder | undefined
@@ -306,6 +303,7 @@ export async function register({
306303
connection.sendNotification(DidChangeWorkspaceFoldersNotification.type, {
307304
event: {
308305
added: [tempWorkspaceFolder],
306+
removed: [],
309307
},
310308
})
311309
}
@@ -316,6 +314,7 @@ export async function register({
316314
if (tempWorkspaceFolder) {
317315
connection.sendNotification(DidChangeWorkspaceFoldersNotification.type, {
318316
event: {
317+
added: [],
319318
removed: [tempWorkspaceFolder],
320319
},
321320
})
@@ -357,16 +356,13 @@ export async function register({
357356
return await fn(connection)
358357
}
359358
const serverRootUri = clientToServerURI(workspaceFolder)
360-
connection = await connect(
361-
workspaceFolder,
362-
{
363-
processId: null,
364-
rootUri: serverRootUri.href,
365-
capabilities: clientCapabilities,
366-
workspaceFolders: null,
367-
initializationOptions,
368-
}
369-
)
359+
connection = await connect(workspaceFolder, {
360+
processId: null,
361+
rootUri: serverRootUri.href,
362+
capabilities: clientCapabilities,
363+
workspaceFolders: null,
364+
initializationOptions,
365+
})
370366
subscriptions.add(connection)
371367
try {
372368
return await fn(connection)
@@ -380,16 +376,13 @@ export async function register({
380376
const connectionPromise = (async () => {
381377
try {
382378
const serverRootUri = clientToServerURI(new URL(root.uri.toString()))
383-
const connection = await connect(
384-
new URL(root.uri.toString()),
385-
{
386-
processId: null,
387-
rootUri: serverRootUri.href,
388-
capabilities: clientCapabilities,
389-
workspaceFolders: null,
390-
initializationOptions,
391-
}
392-
)
379+
const connection = await connect(new URL(root.uri.toString()), {
380+
processId: null,
381+
rootUri: serverRootUri.href,
382+
capabilities: clientCapabilities,
383+
workspaceFolders: null,
384+
initializationOptions,
385+
})
393386
subscriptions.add(connection)
394387
return connection
395388
} catch (err) {

src/logging.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export const redact = (message: string): string => message.replace(/(https?:\/\/
5454
* Logger that formats the logged values and removes any auth info in URLs.
5555
*/
5656
export class RedactingLogger extends AbstractLogger {
57-
constructor(private logger: Logger) {
57+
constructor(private readonly logger: Logger) {
5858
super()
5959
}
6060

@@ -66,7 +66,7 @@ export class RedactingLogger extends AbstractLogger {
6666
}
6767

6868
export class PrefixedLogger extends AbstractLogger {
69-
constructor(private logger: Logger, private prefix: string) {
69+
constructor(private readonly logger: Logger, private readonly prefix: string) {
7070
super()
7171
}
7272

src/lsp-conversion.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export const convertDiagnosticToDecoration = (
8888
diagnostic: Diagnostic
8989
): sourcegraph.TextDocumentDecoration => ({
9090
after: {
91-
color: DIAGNOSTIC_COLORS[diagnostic.severity || DiagnosticSeverity.Hint],
91+
color: DIAGNOSTIC_COLORS[diagnostic.severity ?? DiagnosticSeverity.Hint],
9292
contentText: diagnostic.message,
9393
},
9494
range: convertRange(sourcegraph, diagnostic.range),

src/test/integration.test.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ describe('register()', () => {
4444
server.initialize,
4545
sinon.match({
4646
rootUri: null,
47-
workspaceFolders: [{ name: '', uri: 'git://repo1?rev' }, { name: '', uri: 'git://repo2?rev' }],
47+
workspaceFolders: [
48+
{ name: '', uri: 'git://repo1?rev' },
49+
{ name: '', uri: 'git://repo2?rev' },
50+
],
4851
})
4952
)
5053
})
@@ -109,17 +112,15 @@ describe('register()', () => {
109112
},
110113
})
111114
),
112-
'textDocument/references': sinon.spy(
113-
(params: ReferenceParams): Location[] => [
114-
{
115-
uri: new URL('bar.ts', repoRoot).href,
116-
range: {
117-
start: { line: 1, character: 2 },
118-
end: { line: 3, character: 4 },
119-
},
115+
'textDocument/references': sinon.spy((params: ReferenceParams): Location[] => [
116+
{
117+
uri: new URL('bar.ts', repoRoot).href,
118+
range: {
119+
start: { line: 1, character: 2 },
120+
end: { line: 3, character: 4 },
120121
},
121-
]
122-
),
122+
},
123+
]),
123124
}
124125
const createConnection = stubTransport(server)
125126

yarn.lock

Lines changed: 10 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,7 +1546,7 @@ debug@^4.0.0, debug@^4.1.0, debug@^4.1.1:
15461546
dependencies:
15471547
ms "^2.1.1"
15481548

1549-
debuglog@*, debuglog@^1.0.1:
1549+
debuglog@^1.0.1:
15501550
version "1.0.1"
15511551
resolved "https://registry.npmjs.org/debuglog/-/debuglog-1.0.1.tgz#aa24ffb9ac3df9a2351837cfb2d279360cd78492"
15521552
integrity sha1-qiT/uaw9+aI1GDfPstJ5NgzXhJI=
@@ -2653,7 +2653,7 @@ import-lazy@^2.1.0:
26532653
resolved "https://registry.npmjs.org/import-lazy/-/import-lazy-2.1.0.tgz#05698e3d45c88e8d7e9d92cb0584e77f096f3e43"
26542654
integrity sha1-BWmOPUXIjo1+nZLLBYTnfwlvPkM=
26552655

2656-
imurmurhash@*, imurmurhash@^0.1.4:
2656+
imurmurhash@^0.1.4:
26572657
version "0.1.4"
26582658
resolved "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea"
26592659
integrity sha1-khi5srkoojixPcT7a21XbyMUU+o=
@@ -3410,11 +3410,6 @@ lockfile@^1.0.4:
34103410
dependencies:
34113411
signal-exit "^3.0.2"
34123412

3413-
lodash._baseindexof@*:
3414-
version "3.1.0"
3415-
resolved "https://registry.yarnpkg.com/lodash._baseindexof/-/lodash._baseindexof-3.1.0.tgz#fe52b53a1c6761e42618d654e4a25789ed61822c"
3416-
integrity sha1-/lK1OhxnYeQmGNZU5KJXie1hgiw=
3417-
34183413
lodash._baseuniq@~4.6.0:
34193414
version "4.6.0"
34203415
resolved "https://registry.npmjs.org/lodash._baseuniq/-/lodash._baseuniq-4.6.0.tgz#0ebb44e456814af7905c6212fa2c9b2d51b841e8"
@@ -3423,33 +3418,11 @@ lodash._baseuniq@~4.6.0:
34233418
lodash._createset "~4.0.0"
34243419
lodash._root "~3.0.0"
34253420

3426-
lodash._bindcallback@*:
3427-
version "3.0.1"
3428-
resolved "https://registry.yarnpkg.com/lodash._bindcallback/-/lodash._bindcallback-3.0.1.tgz#e531c27644cf8b57a99e17ed95b35c748789392e"
3429-
integrity sha1-5THCdkTPi1epnhftlbNcdIeJOS4=
3430-
3431-
lodash._cacheindexof@*:
3432-
version "3.0.2"
3433-
resolved "https://registry.yarnpkg.com/lodash._cacheindexof/-/lodash._cacheindexof-3.0.2.tgz#3dc69ac82498d2ee5e3ce56091bafd2adc7bde92"
3434-
integrity sha1-PcaayCSY0u5ePOVgkbr9Ktx73pI=
3435-
3436-
lodash._createcache@*:
3437-
version "3.1.2"
3438-
resolved "https://registry.yarnpkg.com/lodash._createcache/-/lodash._createcache-3.1.2.tgz#56d6a064017625e79ebca6b8018e17440bdcf093"
3439-
integrity sha1-VtagZAF2JeeevKa4AY4XRAvc8JM=
3440-
dependencies:
3441-
lodash._getnative "^3.0.0"
3442-
34433421
lodash._createset@~4.0.0:
34443422
version "4.0.3"
34453423
resolved "https://registry.npmjs.org/lodash._createset/-/lodash._createset-4.0.3.tgz#0f4659fbb09d75194fa9e2b88a6644d363c9fe26"
34463424
integrity sha1-D0ZZ+7CddRlPqeK4imZE02PJ/iY=
34473425

3448-
lodash._getnative@*, lodash._getnative@^3.0.0:
3449-
version "3.9.1"
3450-
resolved "https://registry.yarnpkg.com/lodash._getnative/-/lodash._getnative-3.9.1.tgz#570bc7dede46d61cdcde687d65d3eecbaa3aaff5"
3451-
integrity sha1-VwvH3t5G1hzc3mh9ZdPuy6o6r/U=
3452-
34533426
lodash._reinterpolate@~3.0.0:
34543427
version "3.0.0"
34553428
resolved "https://registry.npmjs.org/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz#0ccf2d89166af03b3663c796538b75ac6e114d9d"
@@ -3495,11 +3468,6 @@ lodash.isstring@^4.0.1:
34953468
resolved "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz#d527dfb5456eca7cc9bb95d5daeaf88ba54a5451"
34963469
integrity sha1-1SfftUVuynzJu5XV2ur4i6VKVFE=
34973470

3498-
lodash.restparam@*:
3499-
version "3.6.1"
3500-
resolved "https://registry.yarnpkg.com/lodash.restparam/-/lodash.restparam-3.6.1.tgz#936a4e309ef330a7645ed4145986c85ae5b20805"
3501-
integrity sha1-k2pOMJ7zMKdkXtQUWYbIWuWyCAU=
3502-
35033471
lodash.set@^4.3.2:
35043472
version "4.3.2"
35053473
resolved "https://registry.npmjs.org/lodash.set/-/lodash.set-4.3.2.tgz#d8757b1da807dde24816b0d6a84bea1a76230b23"
@@ -4205,7 +4173,6 @@ npm@^6.10.3:
42054173
cmd-shim "^3.0.3"
42064174
columnify "~1.5.4"
42074175
config-chain "^1.1.12"
4208-
debuglog "*"
42094176
detect-indent "~5.0.0"
42104177
detect-newline "^2.1.0"
42114178
dezalgo "~1.0.3"
@@ -4220,7 +4187,6 @@ npm@^6.10.3:
42204187
has-unicode "~2.0.1"
42214188
hosted-git-info "^2.8.5"
42224189
iferr "^1.0.2"
4223-
imurmurhash "*"
42244190
infer-owner "^1.0.4"
42254191
inflight "~1.0.6"
42264192
inherits "^2.0.4"
@@ -4239,14 +4205,8 @@ npm@^6.10.3:
42394205
libnpx "^10.2.0"
42404206
lock-verify "^2.1.0"
42414207
lockfile "^1.0.4"
4242-
lodash._baseindexof "*"
42434208
lodash._baseuniq "~4.6.0"
4244-
lodash._bindcallback "*"
4245-
lodash._cacheindexof "*"
4246-
lodash._createcache "*"
4247-
lodash._getnative "*"
42484209
lodash.clonedeep "~4.5.0"
4249-
lodash.restparam "*"
42504210
lodash.union "~4.6.0"
42514211
lodash.uniq "~4.5.0"
42524212
lodash.without "~4.4.0"
@@ -4794,10 +4754,10 @@ prepend-http@^1.0.1:
47944754
resolved "https://registry.npmjs.org/prepend-http/-/prepend-http-1.0.4.tgz#d4f4562b0ce3696e41ac52d0e002e57a635dc6dc"
47954755
integrity sha1-1PRWKwzjaW5BrFLQ4ALlemNdxtw=
47964756

4797-
prettier@^1.16.4:
4798-
version "1.16.4"
4799-
resolved "https://registry.npmjs.org/prettier/-/prettier-1.16.4.tgz#73e37e73e018ad2db9c76742e2647e21790c9717"
4800-
integrity sha512-ZzWuos7TI5CKUeQAtFd6Zhm2s6EpAD/ZLApIhsF9pRvRtM1RFo61dM/4MSRUA0SuLugA/zgrZD8m0BaY46Og7g==
4757+
prettier@^1.19.1:
4758+
version "1.19.1"
4759+
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.19.1.tgz#f7d7f5ff8a9cd872a7be4ca142095956a60797cb"
4760+
integrity sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==
48014761

48024762
process-nextick-args@~2.0.0:
48034763
version "2.0.0"
@@ -6123,10 +6083,10 @@ typedarray@^0.0.6:
61236083
resolved "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
61246084
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=
61256085

6126-
typescript@^3.2.2:
6127-
version "3.2.2"
6128-
resolved "https://registry.npmjs.org/typescript/-/typescript-3.2.2.tgz#fe8101c46aa123f8353523ebdcf5730c2ae493e5"
6129-
integrity sha512-VCj5UiSyHBjwfYacmDuc/NOk4QQixbE+Wn7MFJuS0nRuPQbof132Pw4u53dm264O8LPc2MVsc7RJNml5szurkg==
6086+
typescript@^3.7.4:
6087+
version "3.7.4"
6088+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.7.4.tgz#1743a5ec5fef6a1fa9f3e4708e33c81c73876c19"
6089+
integrity sha512-A25xv5XCtarLwXpcDNZzCGvW2D1S3/bACratYBx2sax8PefsFhlYmkQicKHvpYflFS8if4zne5zT5kpJ7pzuvw==
61306090

61316091
uglify-js@^3.1.4:
61326092
version "3.4.9"

0 commit comments

Comments
 (0)