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

Commit 94d914d

Browse files
committed
wip on lsp-client (must yarn link @sourcegraph/lsp-client with changes from sourcegraph/lsp-client#11
1 parent ad7d1c4 commit 94d914d

File tree

3 files changed

+109
-36
lines changed

3 files changed

+109
-36
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@
153153
},
154154
"dependencies": {
155155
"@sourcegraph/basic-code-intel": "6.0.16",
156+
"@sourcegraph/lsp-client": "^2.0.0-beta.1",
156157
"@sourcegraph/vscode-ws-jsonrpc": "0.0.3-fork",
157158
"prettier": "^1.16.4",
158159
"rxjs": "^6.3.3",

src/lang-go.ts

Lines changed: 76 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as lspClient from '@sourcegraph/lsp-client'
12
import '@babel/polyfill'
23

34
import { activateBasicCodeIntel, registerFeedbackButton } from '@sourcegraph/basic-code-intel'
@@ -26,6 +27,7 @@ import {
2627
import { ConsoleLogger, createWebSocketConnection } from '@sourcegraph/vscode-ws-jsonrpc'
2728
import gql from 'tagged-template-noop'
2829
import { Settings } from './settings'
30+
import { TextDocument } from 'sourcegraph'
2931

3032
// If we can rid ourselves of file:// URIs, this type won't be necessary and we
3133
// can use lspext.Xreference directly.
@@ -739,11 +741,43 @@ const DUMMY_CTX = { subscriptions: { add: (_unsubscribable: any) => void 0 } }
739741

740742
export function activate(ctx: sourcegraph.ExtensionContext = DUMMY_CTX): void {
741743
async function afterActivate(): Promise<void> {
742-
const address = sourcegraph.configuration.get<Settings>().get('go.serverUrl')
743-
if (address) {
744-
ctx.subscriptions.add(registerFeedbackButton({ languageID: 'go', sourcegraph, isPrecise: true }))
744+
if (Math.random() < 0) {
745+
const address = sourcegraph.configuration.get<Settings>().get('go.serverUrl')
746+
if (address) {
747+
ctx.subscriptions.add(registerFeedbackButton({ languageID: 'go', sourcegraph, isPrecise: true }))
748+
await activateUsingWebSockets(ctx)
749+
} else {
750+
activateBasicCodeIntel({
751+
sourcegraph,
752+
languageID: 'go',
753+
fileExts: ['go'],
754+
filterDefinitions: ({ repo, filePath, pos, fileContent, results }) => {
755+
const currentFileImportedPaths = fileContent
756+
.split('\n')
757+
.map(line => {
758+
// Matches the import at index 3
759+
const match = /^(import |\t)(\w+ |\. )?"(.*)"$/.exec(line)
760+
return match ? match[3] : undefined
761+
})
762+
.filter((x): x is string => Boolean(x))
763+
764+
const currentFileImportPath = repo + '/' + path.dirname(filePath)
765+
766+
const filteredResults = results.filter(result => {
767+
const resultImportPath = result.repo + '/' + path.dirname(result.file)
768+
return (
769+
currentFileImportedPaths.some(i => resultImportPath.includes(i)) ||
770+
resultImportPath === currentFileImportPath
771+
)
772+
})
745773

746-
await activateUsingWebSockets(ctx)
774+
return filteredResults.length === 0 ? results : filteredResults
775+
},
776+
commentStyle: {
777+
lineRegex: /\/\/\s?/,
778+
},
779+
})(ctx)
780+
}
747781
} else {
748782
ctx.subscriptions.add(
749783
registerFeedbackButton({
@@ -753,36 +787,45 @@ export function activate(ctx: sourcegraph.ExtensionContext = DUMMY_CTX): void {
753787
})
754788
)
755789

756-
activateBasicCodeIntel({
757-
sourcegraph,
758-
languageID: 'go',
759-
fileExts: ['go'],
760-
filterDefinitions: ({ repo, filePath, pos, fileContent, results }) => {
761-
const currentFileImportedPaths = fileContent
762-
.split('\n')
763-
.map(line => {
764-
// Matches the import at index 3
765-
const match = /^(import |\t)(\w+ |\. )?"(.*)"$/.exec(line)
766-
return match ? match[3] : undefined
767-
})
768-
.filter((x): x is string => Boolean(x))
769-
770-
const currentFileImportPath = repo + '/' + path.dirname(filePath)
771-
772-
const filteredResults = results.filter(result => {
773-
const resultImportPath = result.repo + '/' + path.dirname(result.file)
774-
return (
775-
currentFileImportedPaths.some(i => resultImportPath.includes(i)) ||
776-
resultImportPath === currentFileImportPath
777-
)
790+
const token = await getOrTryToCreateAccessToken()
791+
if (!token) {
792+
// console.log('No token')
793+
} else {
794+
// tslint:disable-next-line: no-empty
795+
const noop = () => {}
796+
797+
const serverURL = sourcegraph.configuration.get<Settings>().value['go.serverUrl']
798+
if (serverURL) {
799+
const client = await lspClient.register({
800+
sourcegraph,
801+
transport: lspClient.webSocketTransport({
802+
serverUrl: serverURL,
803+
logger: {
804+
error: noop,
805+
warn: noop,
806+
info: noop,
807+
log: noop,
808+
},
809+
}),
810+
documentSelector: [{ language: 'go' }],
811+
// clientToServerURI: uri => ..., // optional
812+
// serverToClientURI: uri => ..., // optional
813+
initializationOptions: (url: URL) => {
814+
url.hash = ''
815+
return {
816+
zipURL: constructZipURL({
817+
repoName: pathname(url.href).replace(/^\/+/, ''),
818+
revision: url.search.substr(1),
819+
token,
820+
}),
821+
}
822+
},
778823
})
779-
780-
return filteredResults.length === 0 ? results : filteredResults
781-
},
782-
commentStyle: {
783-
lineRegex: /\/\/\s?/,
784-
},
785-
})(ctx)
824+
ctx.subscriptions.add(client)
825+
} else {
826+
// console.log('No go.serverUrl set')
827+
}
828+
}
786829
}
787830
}
788831
setTimeout(afterActivate, 100)

yarn.lock

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,20 @@
714714
resolved "https://registry.yarnpkg.com/@sourcegraph/prettierrc/-/prettierrc-3.0.0.tgz#716b64b287565f98f539f76bea206912ab4d03b3"
715715
integrity sha512-ziLujsC3IESHGYdtiJ7yVjte9i7mr6jKWTYtCVqgOWeY1Er0/xsQ/sdZIyK61tD282wvd7VjS4pk5RoGEN7biw==
716716

717+
"@sourcegraph/lsp-client@^2.0.0-beta.1":
718+
version "2.0.0-beta.1"
719+
resolved "https://registry.yarnpkg.com/@sourcegraph/lsp-client/-/lsp-client-2.0.0-beta.1.tgz#d231d8caba53a1ff70de20f7b442c2ea439d3b37"
720+
integrity sha512-hho0weMoCxKk96hYkj4re7B6JxY+NccfUm2pgv0+YUKBDWRijqO8sqlgOsN8tl+H1s7UjvE7xw//cENI1N+NGA==
721+
dependencies:
722+
"@sourcegraph/vscode-ws-jsonrpc" "^0.0.3-fork"
723+
lodash "^4.17.11"
724+
rxjs "^6.4.0"
725+
sourcegraph "^22.0.0"
726+
type-zoo "^3.2.1"
727+
uuid "^3.3.2"
728+
vscode-languageserver-protocol "^3.14.1"
729+
vscode-languageserver-types "^3.14.0"
730+
717731
"@sourcegraph/tsconfig@^4.0.0":
718732
version "4.0.0"
719733
resolved "https://registry.yarnpkg.com/@sourcegraph/tsconfig/-/tsconfig-4.0.0.tgz#dd2a406f90760bb789fd89fde4bd0a8d681f2767"
@@ -728,7 +742,7 @@
728742
tslint-config-prettier "^1.6.0"
729743
tslint-react "^3.2.0"
730744

731-
"@sourcegraph/vscode-ws-jsonrpc@0.0.3-fork":
745+
"@sourcegraph/vscode-ws-jsonrpc@0.0.3-fork", "@sourcegraph/vscode-ws-jsonrpc@^0.0.3-fork":
732746
version "0.0.3-fork"
733747
resolved "https://registry.yarnpkg.com/@sourcegraph/vscode-ws-jsonrpc/-/vscode-ws-jsonrpc-0.0.3-fork.tgz#83728a14616ef0587298e7849d960b61853a9954"
734748
integrity sha512-EJLq/ni66glk3xYyOZtUIEbjTCw8kMI6RvO0YQtPd+4um2+aTSM1LfN4NrsiVrRkG7EG/U2OkFlKqT8mGo6w4Q==
@@ -4834,7 +4848,7 @@ rxjs-tslint-rules@^4.12.0:
48344848
tslib "^1.8.0"
48354849
tsutils "^3.0.0"
48364850

4837-
rxjs@^6.3.3:
4851+
rxjs@^6.3.3, rxjs@^6.4.0:
48384852
version "6.4.0"
48394853
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.4.0.tgz#f3bb0fe7bda7fb69deac0c16f17b50b0b8790504"
48404854
integrity sha512-Z9Yfa11F6B9Sg/BK9MnqnQ+aQYicPLtilXBp2yUtDt2JRCE0h26d33EnfO3ZxoNxG0T92OUucP3Ct7cpfkdFfw==
@@ -5066,6 +5080,11 @@ source-map@^0.5.0, source-map@^0.5.3, source-map@^0.5.6:
50665080
dependencies:
50675081
vscode-languageserver-types "^3.12.0"
50685082

5083+
sourcegraph@^22.0.0:
5084+
version "22.0.0"
5085+
resolved "https://registry.yarnpkg.com/sourcegraph/-/sourcegraph-22.0.0.tgz#b259929c31bf367f5160056698a881dc26eb36bd"
5086+
integrity sha512-cJHby0OPCM0y0BmRTKhY89D02f9koROluHMJGQGNE8q9CoIVbe1s6ctHCytz7bjY9mKtCpQMbtxYQhfIm5S4lg==
5087+
50695088
sourcegraph@^23.0.0:
50705089
version "23.0.0"
50715090
resolved "https://registry.yarnpkg.com/sourcegraph/-/sourcegraph-23.0.0.tgz#1fb96015af3e84cc9cc2944823f04a7e952ed565"
@@ -5482,6 +5501,11 @@ type-check@~0.3.2:
54825501
dependencies:
54835502
prelude-ls "~1.1.2"
54845503

5504+
type-zoo@^3.2.1:
5505+
version "3.3.0"
5506+
resolved "https://registry.yarnpkg.com/type-zoo/-/type-zoo-3.3.0.tgz#d5b59393b09a48ac30380c50e2369e828817e9b3"
5507+
integrity sha512-ID2kIg4QMbujPOpphFvSl7yyk0JaN2+5m2cprhxpzJqYWHhozLbYOHCAZqq7j1PPfzLe8XrYeZfPb99v96WVRw==
5508+
54855509
typedarray@^0.0.6:
54865510
version "0.0.6"
54875511
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
@@ -5599,6 +5623,11 @@ util@0.10.3, util@^0.10.3:
55995623
dependencies:
56005624
inherits "2.0.1"
56015625

5626+
uuid@^3.3.2:
5627+
version "3.3.2"
5628+
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.3.2.tgz#1b4af4955eb3077c501c23872fc6513811587131"
5629+
integrity sha512-yXJmeNaw3DnnKAOKJE51sL/ZaYfWJRl1pK9dr19YFCu0ObS231AB1/LbqTKRAQ5kw8A90rA6fr4riOUpTZvQZA==
5630+
56025631
v8-compile-cache@^2.0.0:
56035632
version "2.0.2"
56045633
resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.0.2.tgz#a428b28bb26790734c4fc8bc9fa106fccebf6a6c"
@@ -5642,7 +5671,7 @@ vscode-languageserver-protocol@^3.14.1:
56425671
vscode-jsonrpc "^4.0.0"
56435672
vscode-languageserver-types "3.14.0"
56445673

5645-
vscode-languageserver-types@3.14.0, vscode-languageserver-types@^3.12.0:
5674+
vscode-languageserver-types@3.14.0, vscode-languageserver-types@^3.12.0, vscode-languageserver-types@^3.14.0:
56465675
version "3.14.0"
56475676
resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.14.0.tgz#d3b5952246d30e5241592b6dde8280e03942e743"
56485677
integrity sha512-lTmS6AlAlMHOvPQemVwo3CezxBp0sNB95KNPkqp3Nxd5VFEnuG1ByM0zlRWos0zjO3ZWtkvhal0COgiV1xIA4A==

0 commit comments

Comments
 (0)