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

Commit 3907886

Browse files
committed
WIP
1 parent 656a70a commit 3907886

File tree

3 files changed

+59
-36
lines changed

3 files changed

+59
-36
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
},
2222
"dependencies": {
2323
"@sourcegraph/prettierrc": "^2.2.0",
24+
"rxjs": "^6.3.2",
2425
"vscode-ws-jsonrpc": "^0.0.1-alpha.5"
2526
}
2627
}

src/extension.ts

Lines changed: 57 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,68 @@
11
import * as sourcegraph from 'sourcegraph'
22
import * as rpc from 'vscode-ws-jsonrpc'
3+
import { BehaviorSubject, Unsubscribable, Subscription, EMPTY, of } from 'rxjs'
4+
import { map, switchMap, distinct, distinctUntilChanged } from 'rxjs/operators'
35

4-
const PORT = 1234
6+
interface FullSettings {
7+
'graphql.langserver-address': string
8+
}
9+
10+
type Settings = Partial<FullSettings>
11+
12+
function connectTo(address: string): Promise<rpc.MessageConnection> {
13+
return new Promise(resolve => {
14+
const webSocket = new WebSocket('ws://' + address)
15+
rpc.listen({
16+
webSocket,
17+
onConnection: (connection: rpc.MessageConnection) => {
18+
resolve(connection)
19+
},
20+
})
21+
})
22+
}
523

624
export function activate(): void {
7-
const webSocket = new WebSocket('ws://localhost:' + PORT)
8-
rpc.listen({
9-
webSocket,
10-
onConnection: (connection: rpc.MessageConnection) => {
11-
connection.listen()
25+
const address = sourcegraph.configuration.get<Settings>().get('graphql.langserver-address')
26+
if (!address) {
27+
console.log('No graphql.langserver-address was set, exiting.')
28+
return
29+
}
30+
console.log('Connecting to', address)
1231

13-
sourcegraph.languages.registerHoverProvider(['*'], {
14-
provideHover: async (doc, pos) => {
15-
return connection.sendRequest<sourcegraph.Hover>('hover', doc, pos).then(hover => {
16-
return (
17-
hover && {
18-
contents: {
19-
value: '```python\n' + (hover.contents as any).join('\n') + '\n```',
20-
kind: sourcegraph.MarkupKind.Markdown,
21-
},
22-
}
23-
)
24-
})
25-
},
26-
})
32+
connectTo(address).then((connection: rpc.MessageConnection) => {
33+
console.log('Connected')
34+
connection.listen()
35+
36+
sourcegraph.languages.registerHoverProvider(['*'], {
37+
provideHover: async (doc, pos) => {
38+
return connection.sendRequest<sourcegraph.Hover>('hover', doc, pos).then(hover => {
39+
return (
40+
hover && {
41+
contents: {
42+
value: '```python\n' + (hover.contents as any).join('\n') + '\n```',
43+
kind: sourcegraph.MarkupKind.Markdown,
44+
},
45+
}
46+
)
47+
})
48+
},
49+
})
2750

28-
sourcegraph.languages.registerDefinitionProvider(['*'], {
29-
provideDefinition: async (doc, pos) => {
30-
return connection.sendRequest<any>('definition', doc, pos).then(definition => {
31-
return (
32-
definition &&
33-
new sourcegraph.Location(
34-
new sourcegraph.URI(doc.uri),
35-
new sourcegraph.Range(
36-
new sourcegraph.Position(definition.start.line, definition.start.character),
37-
new sourcegraph.Position(definition.end.line, definition.end.character)
38-
)
51+
sourcegraph.languages.registerDefinitionProvider(['*'], {
52+
provideDefinition: async (doc, pos) => {
53+
return connection.sendRequest<any>('definition', doc, pos).then(definition => {
54+
return (
55+
definition &&
56+
new sourcegraph.Location(
57+
new sourcegraph.URI(doc.uri),
58+
new sourcegraph.Range(
59+
new sourcegraph.Position(definition.start.line, definition.start.character),
60+
new sourcegraph.Position(definition.end.line, definition.end.character)
3961
)
4062
)
41-
})
42-
},
43-
})
44-
},
63+
)
64+
})
65+
},
66+
})
4567
})
4668
}

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3522,7 +3522,7 @@ ripemd160@^2.0.0, ripemd160@^2.0.1:
35223522

35233523
rxjs@^6.3.2:
35243524
version "6.3.2"
3525-
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.3.2.tgz#6a688b16c4e6e980e62ea805ec30648e1c60907f"
3525+
resolved "https://registry.npmjs.org/rxjs/-/rxjs-6.3.2.tgz#6a688b16c4e6e980e62ea805ec30648e1c60907f"
35263526
dependencies:
35273527
tslib "^1.9.0"
35283528

0 commit comments

Comments
 (0)