Skip to content

Commit af1ae73

Browse files
committed
initial commit
0 parents  commit af1ae73

14 files changed

Lines changed: 6087 additions & 0 deletions

‎.editorconfig‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[*]
2+
insert_final_newline = true
3+
end_of_line = lf
4+
charset = utf-8
5+
trim_trailing_whitespace = true
6+
indent_style = space
7+
indent_size = 4
8+
9+
[*.{json,js,yml}]
10+
indent_size = 2
11+
12+
[*.md]
13+
trim_trailing_whitespace = false

‎.gitignore‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dist/
2+
node_modules/
3+
.cache/

‎.prettierignore‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
node_modules/
2+
.git/
3+
coverage/
4+
.cache/
5+
lib/
6+
dist/
7+
package.json
8+
package-lock.json

‎.prettierrc‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"semi": false,
3+
"trailingComma": "es5",
4+
"singleQuote": true,
5+
"useTabs": false
6+
}

‎README.md‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Python
2+
3+
This extension adds Python code intelligence to Sourcegraph using a [Python language server](https://github.com/Microsoft/python-language-server) (the [@sourcegraph fork](https://github.com/sourcegraph/python-language-server/tree/wip2)).
4+
5+
[**🗃️ Source code**](https://github.com/sourcegraph/sourcegraph-python)
6+
7+
[**➕ View in extension registry**](https://sourcegraph.com/extensions/sourcegraph/python)
8+
9+
## Features
10+
11+
For Python code viewed on [Sourcegraph](https://sourcegraph.com) and when using the [Sourcegraph browser extension](https://docs.sourcegraph.com/integration/browser_extension):
12+
13+
- Hovers with documentation and inferred type signatures
14+
- Go to definition
15+
- Find references
16+
17+
## Usage
18+
19+
This extension is enabled for all users by default on Sourcegraph.com and when using the [Sourcegraph browser extension](https://docs.sourcegraph.com/integration/browser_extension) on public code.
20+
21+
To use it, just visit a Python file and hover over tokens. Examples:
22+
23+
- Tensorflow: [tensorflow_ranking/examples/tf_ranking_libsvm.py](https://sourcegraph.com/github.com/tensorflow/ranking@931e4e18d68612d0b29dc3c81994acdd4b6ab743/-/blob/tensorflow_ranking/examples/tf_ranking_libsvm.py#L294:27&tab=references)
24+
- Flask: [flask/views.py](https://sourcegraph.com/github.com/pallets/flask/-/blob/flask/views.py)
25+
- Zulip: [corporate/lib/stripe.py](https://sourcegraph.com/github.com/zulip/zulip/-/blob/corporate/lib/stripe.py)
26+
- Trivial sample: [pkg0/m0.py](http://sourcegraph.com/github.com/sgtest/python-sample-0/-/blob/pkg0/m0.py)
27+
28+
![Screenshot](https://user-images.githubusercontent.com/1976/49628952-d4c92800-f99b-11e8-9605-d880b733cde6.png)
29+
30+
### On self-hosted Sourcegraph instances
31+
32+
_Documentation to be added soon._
33+
34+
## Known issues
35+
36+
- Dependencies are not installed. Hovers, definitions, and references only work for sources checked into the single repository you are viewing.
37+
- Cross-repository definitions and references are not yet supported.

‎package.json‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"name": "python",
3+
"title": "Python",
4+
"description": "Python code intelligence (using the Python language server)",
5+
"publisher": "sourcegraph",
6+
"activationEvents": [
7+
"onLanguage:python"
8+
],
9+
"repository": {
10+
"type": "git",
11+
"url": "https://github.com/sourcegraph/sourcegraph-python"
12+
},
13+
"contributes": {
14+
"configuration": {
15+
"title": "Python settings",
16+
"properties": {
17+
"python.languageServer.url": {
18+
"description": "The URL to the Python language server (which is an instance of https://github.com/sourcegraph/python-language-server).",
19+
"type": "string",
20+
"format": "uri",
21+
"pattern": "^wss?://"
22+
}
23+
}
24+
}
25+
},
26+
"version": "0.0.0-DEVELOPMENT",
27+
"license": "MIT",
28+
"main": "dist/sourcegraph-python.js",
29+
"scripts": {
30+
"prettier": "prettier '**/*.{js?(on),ts}' --write --list-different",
31+
"tslint": "tslint -p tsconfig.json './src/**/*.ts'",
32+
"typecheck": "tsc -p tsconfig.json",
33+
"build": "parcel build --out-file dist/sourcegraph-python.js src/sourcegraph-python.ts",
34+
"serve": "parcel serve --no-hmr --out-file sourcegraph-python.js src/sourcegraph-python.ts",
35+
"watch:typecheck": "tsc -p tsconfig.json -w",
36+
"watch:build": "tsc -p tsconfig.dist.json -w",
37+
"sourcegraph:prepublish": "npm run build"
38+
},
39+
"browserslist": [
40+
"last 1 Chrome versions",
41+
"last 1 Firefox versions",
42+
"last 1 Edge versions",
43+
"last 1 Safari versions"
44+
],
45+
"devDependencies": {
46+
"@sourcegraph/tsconfig": "^3.0.0",
47+
"@sourcegraph/tslint-config": "^12.0.0",
48+
"parcel-bundler": "^1.10.3",
49+
"prettier": "^1.14.3",
50+
"sourcegraph": "^19.4.0",
51+
"tslint": "^5.11.0",
52+
"tslint-language-service": "^0.9.9",
53+
"typescript": "^3.1.3"
54+
},
55+
"dependencies": {
56+
"@types/ws": "^6.0.1",
57+
"rxjs": "^6.3.3",
58+
"vscode-jsonrpc": "^4.0.0",
59+
"vscode-languageserver-protocol": "^3.13.0",
60+
"vscode-ws-jsonrpc": "^0.0.3",
61+
"ws": "^6.1.0"
62+
}
63+
}

‎screenshot.png‎

280 KB
Loading

‎src/converters.ts‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* Converts to/from Sourcegraph client URIs to the URIs known to the language server.
3+
*/
4+
export interface UriConverter {
5+
toLanguageServer: (clientUri: string) => string
6+
toClient: (languageServerUri: string) => string
7+
}
8+
9+
export function createUriConverter(
10+
originalRootUri: string | null,
11+
actualRootUri: string | null
12+
): UriConverter {
13+
if (!originalRootUri || !actualRootUri) {
14+
throw new Error(
15+
'not yet implemented: null values for originalRootUri and/or actualRootUri'
16+
)
17+
}
18+
return {
19+
toLanguageServer: clientUri => {
20+
let path = clientUri
21+
if (path.startsWith(originalRootUri)) {
22+
path = path.slice(originalRootUri.length)
23+
if (path.startsWith('#')) {
24+
path = path.slice(1)
25+
}
26+
if (!path.startsWith('/')) {
27+
path = '/' + path
28+
}
29+
}
30+
return actualRootUri + path
31+
},
32+
toClient: languageServerUri => {
33+
let path = languageServerUri
34+
if (path.startsWith(actualRootUri)) {
35+
path = path.slice(actualRootUri.length)
36+
if (path.startsWith('/')) {
37+
path = path.slice(1)
38+
}
39+
}
40+
return originalRootUri + '#' + path
41+
},
42+
}
43+
}

0 commit comments

Comments
 (0)