|
| 1 | +import * as sourcegraph from "sourcegraph"; |
| 2 | + |
| 3 | +import * as rpc from "vscode-ws-jsonrpc"; |
| 4 | + |
| 5 | +export function activate(): void { |
| 6 | + const webSocket = new WebSocket("ws://localhost:1234"); |
| 7 | + rpc.listen({ |
| 8 | + webSocket, |
| 9 | + onConnection: (connection: rpc.MessageConnection) => { |
| 10 | + connection.listen(); |
| 11 | + |
| 12 | + sourcegraph.languages.registerHoverProvider(["*"], { |
| 13 | + provideHover: async (doc, pos) => { |
| 14 | + return connection |
| 15 | + .sendRequest<sourcegraph.Hover>("hov", doc, pos) |
| 16 | + .then(v => { |
| 17 | + console.log("recv response hov", v); |
| 18 | + return ( |
| 19 | + v && { |
| 20 | + contents: { |
| 21 | + value: |
| 22 | + "```python\n" + (v.contents as any).join("\n") + "\n```", |
| 23 | + kind: sourcegraph.MarkupKind.Markdown |
| 24 | + } |
| 25 | + } |
| 26 | + ); |
| 27 | + }); |
| 28 | + } |
| 29 | + }); |
| 30 | + |
| 31 | + sourcegraph.languages.registerDefinitionProvider(["*"], { |
| 32 | + provideDefinition: async (doc, pos) => { |
| 33 | + return connection.sendRequest<any>("def", doc, pos).then(v => { |
| 34 | + console.log("recv response def", v); |
| 35 | + return ( |
| 36 | + v && |
| 37 | + new sourcegraph.Location( |
| 38 | + new sourcegraph.URI(doc.uri), |
| 39 | + new sourcegraph.Range( |
| 40 | + new sourcegraph.Position(v.start.line, v.start.character), |
| 41 | + new sourcegraph.Position(v.end.line, v.end.character) |
| 42 | + ) |
| 43 | + ) |
| 44 | + ); |
| 45 | + }); |
| 46 | + } |
| 47 | + }); |
| 48 | + } |
| 49 | + }); |
| 50 | +} |
0 commit comments