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

Commit e196093

Browse files
committed
wip on lsp-client (must yarn link @sourcegraph/lsp-client with changes from sourcegraph/lsp-client#11
1 parent 59b4460 commit e196093

File tree

3 files changed

+108
-34
lines changed

3 files changed

+108
-34
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
},
123123
"dependencies": {
124124
"@sourcegraph/basic-code-intel": "6.0.15",
125+
"@sourcegraph/lsp-client": "^2.0.0-beta.1",
125126
"@sourcegraph/vscode-ws-jsonrpc": "0.0.3-fork",
126127
"prettier": "^1.16.4",
127128
"rxjs": "^6.3.3",

src/lang-go.ts

Lines changed: 75 additions & 31 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 } 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.
@@ -701,40 +703,82 @@ const DUMMY_CTX = { subscriptions: { add: (_unsubscribable: any) => void 0 } }
701703

702704
export function activate(ctx: sourcegraph.ExtensionContext = DUMMY_CTX): void {
703705
async function afterActivate(): Promise<void> {
704-
const address = sourcegraph.configuration.get<Settings>().get('go.serverUrl')
705-
if (address) {
706-
await activateUsingWebSockets(ctx)
707-
} else {
708-
activateBasicCodeIntel({
709-
sourcegraph,
710-
languageID: 'go',
711-
fileExts: ['go'],
712-
filterDefinitions: ({ repo, filePath, pos, fileContent, results }) => {
713-
const currentFileImportedPaths = fileContent
714-
.split('\n')
715-
.map(line => {
716-
// Matches the import at index 3
717-
const match = /^(import |\t)(\w+ |\. )?"(.*)"$/.exec(line)
718-
return match ? match[3] : undefined
706+
if (Math.random() < 0) {
707+
const address = sourcegraph.configuration.get<Settings>().get('go.serverUrl')
708+
if (address) {
709+
await activateUsingWebSockets(ctx)
710+
} else {
711+
activateBasicCodeIntel({
712+
sourcegraph,
713+
languageID: 'go',
714+
fileExts: ['go'],
715+
filterDefinitions: ({ repo, filePath, pos, fileContent, results }) => {
716+
const currentFileImportedPaths = fileContent
717+
.split('\n')
718+
.map(line => {
719+
// Matches the import at index 3
720+
const match = /^(import |\t)(\w+ |\. )?"(.*)"$/.exec(line)
721+
return match ? match[3] : undefined
722+
})
723+
.filter((x): x is string => Boolean(x))
724+
725+
const currentFileImportPath = repo + '/' + path.dirname(filePath)
726+
727+
const filteredResults = results.filter(result => {
728+
const resultImportPath = result.repo + '/' + path.dirname(result.file)
729+
return (
730+
currentFileImportedPaths.some(i => resultImportPath.includes(i)) ||
731+
resultImportPath === currentFileImportPath
732+
)
719733
})
720-
.filter((x): x is string => Boolean(x))
721-
722-
const currentFileImportPath = repo + '/' + path.dirname(filePath)
723734

724-
const filteredResults = results.filter(result => {
725-
const resultImportPath = result.repo + '/' + path.dirname(result.file)
726-
return (
727-
currentFileImportedPaths.some(i => resultImportPath.includes(i)) ||
728-
resultImportPath === currentFileImportPath
729-
)
735+
return filteredResults.length === 0 ? results : filteredResults
736+
},
737+
commentStyle: {
738+
lineRegex: /\/\/\s?/,
739+
},
740+
})(ctx)
741+
}
742+
} else {
743+
const token = await getOrTryToCreateAccessToken()
744+
if (!token) {
745+
// console.log('No token')
746+
} else {
747+
// tslint:disable-next-line: no-empty
748+
const noop = () => {}
749+
750+
const serverURL = sourcegraph.configuration.get<Settings>().value['go.serverUrl']
751+
if (serverURL) {
752+
const client = await lspClient.register({
753+
sourcegraph,
754+
transport: lspClient.webSocketTransport({
755+
serverUrl: serverURL,
756+
logger: {
757+
error: noop,
758+
warn: noop,
759+
info: noop,
760+
log: noop,
761+
},
762+
}),
763+
documentSelector: [{ language: 'go' }],
764+
// clientToServerURI: uri => ..., // optional
765+
// serverToClientURI: uri => ..., // optional
766+
initializationOptions: (url: URL) => {
767+
url.hash = ''
768+
return {
769+
zipURL: constructZipURL({
770+
repoName: pathname(url.href).replace(/^\/+/, ''),
771+
revision: url.search.substr(1),
772+
token,
773+
}),
774+
}
775+
},
730776
})
731-
732-
return filteredResults.length === 0 ? results : filteredResults
733-
},
734-
commentStyle: {
735-
lineRegex: /\/\/\s?/,
736-
},
737-
})(ctx)
777+
ctx.subscriptions.add(client)
778+
} else {
779+
// console.log('No go.serverUrl set')
780+
}
781+
}
738782
}
739783
}
740784
setTimeout(afterActivate, 100)

yarn.lock

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,20 @@
709709
rxjs "^6.3.3"
710710
sourcegraph "^23.0.0"
711711

712+
"@sourcegraph/lsp-client@^2.0.0-beta.1":
713+
version "2.0.0-beta.1"
714+
resolved "https://registry.yarnpkg.com/@sourcegraph/lsp-client/-/lsp-client-2.0.0-beta.1.tgz#d231d8caba53a1ff70de20f7b442c2ea439d3b37"
715+
integrity sha512-hho0weMoCxKk96hYkj4re7B6JxY+NccfUm2pgv0+YUKBDWRijqO8sqlgOsN8tl+H1s7UjvE7xw//cENI1N+NGA==
716+
dependencies:
717+
"@sourcegraph/vscode-ws-jsonrpc" "^0.0.3-fork"
718+
lodash "^4.17.11"
719+
rxjs "^6.4.0"
720+
sourcegraph "^22.0.0"
721+
type-zoo "^3.2.1"
722+
uuid "^3.3.2"
723+
vscode-languageserver-protocol "^3.14.1"
724+
vscode-languageserver-types "^3.14.0"
725+
712726
"@sourcegraph/prettierrc@^2.2.0":
713727
version "2.2.0"
714728
resolved "https://registry.yarnpkg.com/@sourcegraph/prettierrc/-/prettierrc-2.2.0.tgz#af4a6fcd465b0a39a07ffbd8f2d3414d01e603e8"
@@ -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)