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

Commit 8f89a09

Browse files
committed
wip
0 parents  commit 8f89a09

File tree

5 files changed

+4241
-0
lines changed

5 files changed

+4241
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.cache/
2+
dist/
3+
node_modules/

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Token Highlights Sourcegraph Extension
2+
3+
A [Sourcegraph extension](https://github.com/sourcegraph/sourcegraph-extension-api) for highlighting lines matching the currently hovered token on GitHub, Sourcegraph, and other tools.
4+
5+
[**➕ Add to Sourcegraph**](https://sourcegraph.com/extensions/chris/token-highlights)
6+
7+
Source code on GitHub: https://github.com/sourcegraph/sourcegraph-token-highlights
8+
9+
![demo](https://user-images.githubusercontent.com/1387653/45539771-86065a80-b7bf-11e8-8d44-d9878cbae054.gif)

package.json

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "graphql",
3+
"publisher": "chris",
4+
"title": "GraphQL",
5+
"description": "GraphQL code intelligence.",
6+
"repository": {
7+
"type": "git",
8+
"url": "https://github.com/sourcegraph/sourcegraph-token-highlights.git"
9+
},
10+
"activationEvents": [
11+
"*"
12+
],
13+
"main": "dist/extension.js",
14+
"scripts": {
15+
"sourcegraph:prepublish": "parcel build src/extension.ts"
16+
},
17+
"devDependencies": {
18+
"parcel-bundler": "^1.9.7",
19+
"sourcegraph": "^16.0.0",
20+
"typescript": "^3.0.3"
21+
},
22+
"dependencies": {
23+
"vscode-ws-jsonrpc": "^0.0.1-alpha.5"
24+
}
25+
}

src/extension.ts

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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

Comments
 (0)