Skip to content

Commit df31d08

Browse files
committed
initial commit
0 parents  commit df31d08

22 files changed

Lines changed: 1075 additions & 0 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
out
2+
node_modules

.vscode/launch.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// A launch configuration that compiles the extension and then opens it inside a new window
2+
{
3+
"version": "0.1.0",
4+
"configurations": [
5+
{
6+
"name": "Launch Extension",
7+
"type": "extensionHost",
8+
"request": "launch",
9+
"runtimeExecutable": "${execPath}",
10+
"args": ["--extensionDevelopmentPath=${workspaceRoot}" ],
11+
"stopOnEntry": false,
12+
"sourceMaps": true,
13+
"outDir": "out/src",
14+
"preLaunchTask": "npm"
15+
},
16+
{
17+
"name": "Launch Tests",
18+
"type": "extensionHost",
19+
"request": "launch",
20+
"runtimeExecutable": "${execPath}",
21+
"args": ["--extensionDevelopmentPath=${workspaceRoot}", "--extensionTestsPath=${workspaceRoot}/out/test" ],
22+
"stopOnEntry": false,
23+
"sourceMaps": true,
24+
"outDir": "out/test",
25+
"preLaunchTask": "npm"
26+
}
27+
]
28+
}

.vscode/settings.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Place your settings in this file to overwrite default and user settings.
2+
{
3+
"files.exclude": {
4+
"out": false // set this to true to hide the "out" folder with the compiled JS files
5+
},
6+
"search.exclude": {
7+
"out": true // set this to false to include "out" folder in search results
8+
},
9+
"typescript.tsdk": "./node_modules/typescript/lib" // we want to use the TS server from our node_modules folder to control its version
10+
}

.vscode/tasks.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Available variables which can be used inside of strings.
2+
// ${workspaceRoot}: the root folder of the team
3+
// ${file}: the current opened file
4+
// ${fileBasename}: the current opened file's basename
5+
// ${fileDirname}: the current opened file's dirname
6+
// ${fileExtname}: the current opened file's extension
7+
// ${cwd}: the current working directory of the spawned process
8+
9+
// A task runner that calls a custom npm script that compiles the extension.
10+
{
11+
"version": "0.1.0",
12+
13+
// we want to run npm
14+
"command": "npm",
15+
16+
// the command is a shell script
17+
"isShellCommand": true,
18+
19+
// show the output window only if unrecognized errors occur.
20+
"showOutput": "silent",
21+
22+
// we run the custom script "compile" as defined in package.json
23+
"args": ["run", "compile", "--loglevel", "silent"],
24+
25+
// The tsc compiler is started in watching mode
26+
"isWatching": true,
27+
28+
// use the standard tsc in watch mode problem matcher to find compile problems in the output.
29+
"problemMatcher": "$tsc-watch"
30+
}

.vscodeignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.vscode/**
2+
typings/**
3+
out/test/**
4+
test/**
5+
src/**
6+
**/*.map
7+
.gitignore
8+
tsconfig.json
9+
vsc-extension-quickstart.md

LICENSE

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 DonJayamanne
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+
<<<<<<< HEAD
23+
=======
24+
25+
>>>>>>> 9109fe02f8f283de4e481528c428c78c846537db

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Python
2+
3+
Intellisense, auto-completion, rename references, view references, go to definition, and the like,
4+
5+
##Features
6+
* Intellisense and auto completion
7+
* Renaming
8+
* Viewing references
9+
* Going to definitins
10+
* View signature and similar by hovering over a function or method
11+
12+
Open the python file and start using it.
13+
14+
NOTE: Path to Python is assumed to be in the current environment path.
15+
16+
![Image of File History](https://raw.githubusercontent.com/DonJayamanne/pythonVSCode/master/images/fileHistoryCommand.gif)
17+
18+
![Image of another instance of File History](https://raw.githubusercontent.com/DonJayamanne/pythonVSCode/master/images/fileHistoryCommandMore.gif)
19+
20+
![Image of Line History](https://raw.githubusercontent.com/DonJayamanne/pythonVSCode/master/images/lineHistoryCommand.gif)
21+
22+
23+
## Source
24+
25+
[Github](https://github.com/DonJayamanne/pythonVSCode)
26+
27+
## License
28+
29+
[MIT](https://raw.githubusercontent.com/DonJayamanne/pythonVSCode/master/LICENSE)

package.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"name": "python",
3+
"displayName": "Python",
4+
"description": "Python Auto complete",
5+
"version": "0.0.1",
6+
"publisher": "donjayamanne",
7+
"license": "SEE LICENSE IN LICENSE or README.MD",
8+
"homepage": "https://github.com/DonJayamanne/pythonVSCode/blob/master/README.md",
9+
"repository": {
10+
"type": "git",
11+
"url": "https://github.com/DonJayamanne/pythonVSCode"
12+
},
13+
"bugs": {
14+
"url": "https://github.com/DonJayamanne/pythonVSCode/issues"
15+
},
16+
"icon": "images/icon.png",
17+
"galleryBanner": {
18+
"color": "#0000FF",
19+
"theme": "dark"
20+
},
21+
"engines": {
22+
"vscode": "^0.10.1"
23+
},
24+
"categories": [
25+
"Languages"
26+
],
27+
"activationEvents": [
28+
"onLanguage:python"
29+
],
30+
"main": "./out/src/extension",
31+
"contributes": {},
32+
"scripts": {
33+
"vscode:prepublish": "node ./node_modules/vscode/bin/compile",
34+
"compile": "node ./node_modules/vscode/bin/compile -watch -p ./"
35+
},
36+
"devDependencies": {
37+
"typescript": "^1.6.2",
38+
"vscode": "0.10.x"
39+
}
40+
}

src/extension.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// The module 'vscode' contains the VS Code extensibility API
2+
// Import the module and reference it with the alias vscode in your code below
3+
import * as vscode from 'vscode';
4+
import {PythonCompletionItemProvider} from './providers/completionProvider';
5+
import {PythonSignatureHelpProvider} from './providers/signatureProvider';
6+
import {PythonHoverProvider} from './providers/hoverProvider';
7+
import {PythonDefinitionProvider} from './providers/definitionProvider';
8+
import {PythonReferenceProvider} from './providers/referenceProvider';
9+
import {PythonRenameProvider} from './providers/renameProvider';
10+
11+
const PYTHON: vscode.DocumentFilter = { language: 'python', scheme: 'file' }
12+
13+
// this method is called when your extension is activated
14+
// your extension is activated the very first time the command is executed
15+
export function activate(context: vscode.ExtensionContext) {
16+
var rootDir = context.asAbsolutePath(".");
17+
18+
context.subscriptions.push(vscode.languages.registerRenameProvider(PYTHON, new PythonRenameProvider(rootDir)));
19+
context.subscriptions.push(vscode.languages.registerHoverProvider(PYTHON, new PythonHoverProvider(rootDir)));
20+
context.subscriptions.push(vscode.languages.registerSignatureHelpProvider(PYTHON, new PythonSignatureHelpProvider(rootDir), '('));
21+
context.subscriptions.push(vscode.languages.registerDefinitionProvider(PYTHON, new PythonDefinitionProvider(rootDir)));
22+
context.subscriptions.push(vscode.languages.registerReferenceProvider(PYTHON, new PythonReferenceProvider(rootDir)));
23+
context.subscriptions.push(vscode.languages.registerCompletionItemProvider(PYTHON, new PythonCompletionItemProvider(rootDir), '.'));
24+
}
25+
26+
// this method is called when your extension is deactivated
27+
export function deactivate() {
28+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*---------------------------------------------------------
2+
* Copyright (C) Microsoft Corporation. All rights reserved.
3+
*--------------------------------------------------------*/
4+
5+
'use strict';
6+
7+
import vscode = require('vscode');
8+
import cp = require('child_process');
9+
import { dirname, basename } from 'path';
10+
import * as proxy from './jediProxy';
11+
import * as fs from 'fs';
12+
13+
const mappedTypes = {};
14+
mappedTypes["module"] = vscode.CompletionItemKind.Module;
15+
mappedTypes["class"] = vscode.CompletionItemKind.Class;
16+
mappedTypes["instance"] = vscode.CompletionItemKind.Variable;
17+
mappedTypes["function"] = vscode.CompletionItemKind.Function;
18+
mappedTypes["funcdef"] = vscode.CompletionItemKind.Function;
19+
mappedTypes["property"] = vscode.CompletionItemKind.Property;
20+
mappedTypes["import"] = vscode.CompletionItemKind.Module;
21+
mappedTypes["keyword"] = vscode.CompletionItemKind.Keyword;
22+
mappedTypes["builtin"] = vscode.CompletionItemKind.Keyword;
23+
mappedTypes["statement"] = vscode.CompletionItemKind.Value;
24+
mappedTypes["value"] = vscode.CompletionItemKind.Value;
25+
mappedTypes["variable"] = vscode.CompletionItemKind.Variable;
26+
mappedTypes["param"] = vscode.CompletionItemKind.Variable;
27+
mappedTypes["constant"] = vscode.CompletionItemKind.Variable;
28+
29+
export class PythonCompletionItemProvider implements vscode.CompletionItemProvider {
30+
public constructor(rootDir: string) {
31+
proxy.initialize(rootDir);
32+
}
33+
34+
private gocodeConfigurationComplete = false;
35+
36+
public provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken): Thenable<vscode.CompletionItem[]> {
37+
return new Promise<vscode.CompletionItem[]>((resolve, reject) => {
38+
var filename = document.fileName;
39+
if (document.lineAt(position.line).text.match(/^\s*\/\//)) {
40+
return resolve([]);
41+
}
42+
if (position.character <= 0) {
43+
return resolve([]);
44+
}
45+
//if current character is '(', then ignore it
46+
var txt = document.getText(new vscode.Range(new vscode.Position(position.line, position.character - 1), position));
47+
var type = proxy.CommandType.Completions;
48+
var columnIndex = position.character;
49+
if (txt === "(") {
50+
//return resolve([]);
51+
//type = proxy.CommandType.Arguments;
52+
//columnIndex = columnIndex -1;
53+
}
54+
var source = document.getText();//fs.realpathSync(filename).toString();
55+
var cmd: proxy.ICommand = {
56+
id: new Date().getTime().toString(),
57+
command: type,
58+
fileName: filename,
59+
columnIndex: columnIndex,
60+
lineIndex: position.line,
61+
reject: onRejected,
62+
resolve: onResolved,
63+
source: source
64+
};
65+
66+
console.log(cmd.lineIndex.toString() + ":" + cmd.columnIndex.toString());
67+
68+
function onRejected(error) {
69+
if (token.isCancellationRequested) {
70+
return resolve([]);
71+
}
72+
var y = "";
73+
}
74+
function onResolved(data: proxy.ICompletionResult) {
75+
if (token.isCancellationRequested) {
76+
return resolve([]);
77+
}
78+
if (data && data.items.length > 0) {
79+
var items = data.items.map(item=> {
80+
var completionItem = new vscode.CompletionItem(item.text);
81+
completionItem.documentation = item.description;
82+
if (mappedTypes[item.type]) {
83+
completionItem.kind = mappedTypes[item.type];
84+
}
85+
else {
86+
console.error("Unknown type = " + item.type);
87+
}
88+
89+
return completionItem;
90+
//completionItem.kind
91+
//completionItem.kind = vscode.CompletionItemKind.Class
92+
});
93+
resolve(items);
94+
}
95+
else {
96+
resolve([]);
97+
}
98+
}
99+
proxy.sendCommand(cmd).then(onResolved, onRejected);
100+
});
101+
}
102+
}

0 commit comments

Comments
 (0)