GeezerVison is showing github.com — #898 #265 #630 #727 #746 and more · erinxocon/vscode-python@176c477
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: pythonFiles/completion.py +33-7Lines changed: 33 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -103,6 +103,8 @@ def _get_call_signatures(self, script): | 103 | 103 | call_signatures = script.call_signatures() | 104 | 104 | except KeyError: | 105 | 105 | call_signatures = [] | | 106 | + except : | | 107 | + call_signatures = [] | 106 | 108 | for signature in call_signatures: | 107 | 109 | for pos, param in enumerate(signature.params): | 108 | 110 | if not param.name: | @@ -222,6 +224,8 @@ def _serialize_completions(self, script, identifier=None, prefix=''): | 222 | 224 | completions = script.completions() | 223 | 225 | except KeyError: | 224 | 226 | completions = [] | | 227 | + except : | | 228 | + completions = [] | 225 | 229 | for completion in completions: | 226 | 230 | if self.show_doc_strings: | 227 | 231 | try: | @@ -635,18 +639,40 @@ def _process_request(self, request): | 635 | 639 | column=request['column'], path=request.get('path', '')) | 636 | 640 |
| 637 | 641 | if lookup == 'definitions': | 638 | | - defs = self._get_definitionsx(script.goto_definitions(), request['id']) | 639 | | - if len(defs) == 0: | 640 | | - defs = self._get_definitionsx(script.goto_assignments(), request['id']) | | 642 | + defs = [] | | 643 | + try: | | 644 | + defs = self._get_definitionsx(script.goto_assignments(follow_imports=False), request['id']) | | 645 | + except: | | 646 | + pass | | 647 | + try: | | 648 | + if len(defs) == 0: | | 649 | + defs = self._get_definitionsx(script.goto_definitions(), request['id']) | | 650 | + except: | | 651 | + pass | | 652 | + try: | | 653 | + if len(defs) == 0: | | 654 | + defs = self._get_definitionsx(script.goto_assignments(), request['id']) | | 655 | + except: | | 656 | + pass | 641 | 657 | return json.dumps({'id': request['id'], 'results': defs}) | 642 | 658 | if lookup == 'tooltip': | 643 | 659 | if jediPreview: | 644 | | - defs = self._get_definitionsx(script.goto_definitions(), request['id'], True) | 645 | | - if len(defs) == 0: | 646 | | - defs = self._get_definitionsx(script.goto_assignments(), request['id'], True) | | 660 | + defs = [] | | 661 | + try: | | 662 | + defs = self._get_definitionsx(script.goto_definitions(), request['id'], True) | | 663 | + except: | | 664 | + pass | | 665 | + try: | | 666 | + if len(defs) == 0: | | 667 | + defs = self._get_definitionsx(script.goto_assignments(), request['id'], True) | | 668 | + except: | | 669 | + pass | 647 | 670 | return json.dumps({'id': request['id'], 'results': defs}) | 648 | 671 | else: | 649 | | - return self._serialize_tooltip(script.goto_definitions(), request['id']) | | 672 | + try: | | 673 | + return self._serialize_tooltip(script.goto_definitions(), request['id']) | | 674 | + except: | | 675 | + return json.dumps({'id': request['id'], 'results': []}) | 650 | 676 | elif lookup == 'arguments': | 651 | 677 | return self._serialize_arguments( | 652 | 678 | script, request['id']) | |
Collapse file Copy file name to clipboardExpand all lines: requirements.txt +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -8,4 +8,6 @@ pydocstyle==1.0.0 | 8 | 8 | jupyter | 9 | 9 | ipython | 10 | 10 | nose | 11 | | -pytest | | 11 | +pytest | | 12 | +fabric | | 13 | +numba |
Collapse file Copy file name to clipboardExpand all lines: src/test/autocomplete/base.test.ts +57Lines changed: 57 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -17,6 +17,9 @@ let pythonSettings = settings.PythonSettings.getInstance(); | 17 | 17 | let autoCompPath = path.join(__dirname, '..', '..', '..', 'src', 'test', 'pythonFiles', 'autocomp'); | 18 | 18 | const fileOne = path.join(autoCompPath, 'one.py'); | 19 | 19 | const fileImport = path.join(autoCompPath, 'imp.py'); | | 20 | +const fileDoc = path.join(autoCompPath, 'doc.py'); | | 21 | +const fileLambda = path.join(autoCompPath, 'lamb.py'); | | 22 | +const fileDecorator = path.join(autoCompPath, 'deco.py'); | 20 | 23 | const fileEncoding = path.join(autoCompPath, 'four.py'); | 21 | 24 | const fileEncodingUsed = path.join(autoCompPath, 'five.py'); | 22 | 25 |
| @@ -62,6 +65,60 @@ suite('Autocomplete', () => { | 62 | 65 | assert.notEqual(list.items.filter(item => item.label === 'fstat').length, 0, 'fstat not found'); | 63 | 66 | }); | 64 | 67 |
| | 68 | + // https://github.com/DonJayamanne/pythonVSCode/issues/898 | | 69 | + test('For "f.readlines()"', async () => { | | 70 | + const textDocument = await vscode.workspace.openTextDocument(fileDoc); | | 71 | + await vscode.window.showTextDocument(textDocument); | | 72 | + const position = new vscode.Position(5, 27); | | 73 | + const list = await vscode.commands.executeCommand<vscode.CompletionList>('vscode.executeCompletionItemProvider', textDocument.uri, position); | | 74 | + assert.notEqual(list.items.filter(item => item.label === 'capitalize').length, 0, 'capitalize not found (known not to work, Jedi issue)'); | | 75 | + assert.notEqual(list.items.filter(item => item.label === 'upper').length, 0, 'upper not found'); | | 76 | + assert.notEqual(list.items.filter(item => item.label === 'lower').length, 0, 'lower not found'); | | 77 | + }); | | 78 | + | | 79 | + // https://github.com/DonJayamanne/pythonVSCode/issues/265 | | 80 | + test('For "lambda"', async () => { | | 81 | + const textDocument = await vscode.workspace.openTextDocument(fileLambda); | | 82 | + await vscode.window.showTextDocument(textDocument); | | 83 | + const position = new vscode.Position(1, 19); | | 84 | + const list = await vscode.commands.executeCommand<vscode.CompletionList>('vscode.executeCompletionItemProvider', textDocument.uri, position); | | 85 | + assert.notEqual(list.items.filter(item => item.label === 'append').length, 0, 'append not found'); | | 86 | + assert.notEqual(list.items.filter(item => item.label === 'clear').length, 0, 'clear not found'); | | 87 | + assert.notEqual(list.items.filter(item => item.label === 'count').length, 0, 'cound not found'); | | 88 | + }); | | 89 | + | | 90 | + // https://github.com/DonJayamanne/pythonVSCode/issues/630 | | 91 | + test('For "abc.decorators"', async () => { | | 92 | + const textDocument = await vscode.workspace.openTextDocument(fileDecorator); | | 93 | + await vscode.window.showTextDocument(textDocument); | | 94 | + let position = new vscode.Position(3, 9); | | 95 | + let list = await vscode.commands.executeCommand<vscode.CompletionList>('vscode.executeCompletionItemProvider', textDocument.uri, position); | | 96 | + assert.notEqual(list.items.filter(item => item.label === 'ABCMeta').length, 0, 'ABCMeta not found'); | | 97 | + assert.notEqual(list.items.filter(item => item.label === 'abstractmethod').length, 0, 'abstractmethod not found'); | | 98 | + | | 99 | + position = new vscode.Position(4, 9); | | 100 | + list = await vscode.commands.executeCommand<vscode.CompletionList>('vscode.executeCompletionItemProvider', textDocument.uri, position); | | 101 | + assert.notEqual(list.items.filter(item => item.label === 'ABCMeta').length, 0, 'ABCMeta not found'); | | 102 | + assert.notEqual(list.items.filter(item => item.label === 'abstractmethod').length, 0, 'abstractmethod not found'); | | 103 | + | | 104 | + position = new vscode.Position(2, 30); | | 105 | + list = await vscode.commands.executeCommand<vscode.CompletionList>('vscode.executeCompletionItemProvider', textDocument.uri, position); | | 106 | + assert.notEqual(list.items.filter(item => item.label === 'ABCMeta').length, 0, 'ABCMeta not found'); | | 107 | + assert.notEqual(list.items.filter(item => item.label === 'abstractmethod').length, 0, 'abstractmethod not found'); | | 108 | + }); | | 109 | + | | 110 | + // https://github.com/DonJayamanne/pythonVSCode/issues/727 | | 111 | + // https://github.com/DonJayamanne/pythonVSCode/issues/746 | | 112 | + // https://github.com/davidhalter/jedi/issues/859 | | 113 | + test('For "time.slee"', async () => { | | 114 | + const textDocument = await vscode.workspace.openTextDocument(fileDoc); | | 115 | + await vscode.window.showTextDocument(textDocument); | | 116 | + const position = new vscode.Position(10, 9); | | 117 | + const list = await vscode.commands.executeCommand<vscode.CompletionList>('vscode.executeCompletionItemProvider', textDocument.uri, position); | | 118 | + assert.notEqual(list.items.filter(item => item.label === 'sleep').length, 0, 'sleep not found'); | | 119 | + assert.notEqual(list.items.filter(item => item.documentation.startsWith("Delay execution for a given number of seconds. The argument may be")).length, 0, 'Documentation incorrect'); | | 120 | + }); | | 121 | + | 65 | 122 | test('For custom class', done => { | 66 | 123 | let textEditor: vscode.TextEditor; | 67 | 124 | let textDocument: vscode.TextDocument; | |
Collapse file Copy file name to clipboardExpand all lines: src/test/autocomplete/pep526.test.ts +58-2Lines changed: 58 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -38,17 +38,73 @@ suite('Autocomplete PEP 526', () => { | 38 | 38 | closeActiveWindows().then(() => done(), () => done()); | 39 | 39 | }); | 40 | 40 |
| 41 | | - test('variable', async () => { | | 41 | + test('variable (abc:str)', async () => { | 42 | 42 | if (!await isPython3) { | 43 | 43 | return; | 44 | 44 | } | 45 | 45 | let textDocument = await vscode.workspace.openTextDocument(filePep526); | 46 | 46 | await vscode.window.showTextDocument(textDocument); | 47 | 47 | assert(vscode.window.activeTextEditor, 'No active editor'); | 48 | | - const position = new vscode.Position(3, 8); | | 48 | + const position = new vscode.Position(9, 8); | 49 | 49 | let list = await vscode.commands.executeCommand<vscode.CompletionList>('vscode.executeCompletionItemProvider', textDocument.uri, position); | 50 | 50 | assert.notEqual(list.items.filter(item => item.label === 'capitalize').length, 0, 'capitalize not found'); | 51 | 51 | assert.notEqual(list.items.filter(item => item.label === 'upper').length, 0, 'upper not found'); | 52 | 52 | assert.notEqual(list.items.filter(item => item.label === 'lower').length, 0, 'lower not found'); | 53 | 53 | }); | | 54 | + | | 55 | + test('variable (abc: str = "")', async () => { | | 56 | + if (!await isPython3) { | | 57 | + return; | | 58 | + } | | 59 | + let textDocument = await vscode.workspace.openTextDocument(filePep526); | | 60 | + await vscode.window.showTextDocument(textDocument); | | 61 | + assert(vscode.window.activeTextEditor, 'No active editor'); | | 62 | + const position = new vscode.Position(8, 14); | | 63 | + let list = await vscode.commands.executeCommand<vscode.CompletionList>('vscode.executeCompletionItemProvider', textDocument.uri, position); | | 64 | + assert.notEqual(list.items.filter(item => item.label === 'capitalize').length, 0, 'capitalize not found'); | | 65 | + assert.notEqual(list.items.filter(item => item.label === 'upper').length, 0, 'upper not found'); | | 66 | + assert.notEqual(list.items.filter(item => item.label === 'lower').length, 0, 'lower not found'); | | 67 | + }); | | 68 | + | | 69 | + test('variable (abc = UNKNOWN # type: str)', async () => { | | 70 | + if (!await isPython3) { | | 71 | + return; | | 72 | + } | | 73 | + let textDocument = await vscode.workspace.openTextDocument(filePep526); | | 74 | + await vscode.window.showTextDocument(textDocument); | | 75 | + assert(vscode.window.activeTextEditor, 'No active editor'); | | 76 | + const position = new vscode.Position(7, 14); | | 77 | + let list = await vscode.commands.executeCommand<vscode.CompletionList>('vscode.executeCompletionItemProvider', textDocument.uri, position); | | 78 | + assert.notEqual(list.items.filter(item => item.label === 'capitalize').length, 0, 'capitalize not found'); | | 79 | + assert.notEqual(list.items.filter(item => item.label === 'upper').length, 0, 'upper not found'); | | 80 | + assert.notEqual(list.items.filter(item => item.label === 'lower').length, 0, 'lower not found'); | | 81 | + }); | | 82 | + | | 83 | + test('class methods', async () => { | | 84 | + if (!await isPython3) { | | 85 | + return; | | 86 | + } | | 87 | + let textDocument = await vscode.workspace.openTextDocument(filePep526); | | 88 | + await vscode.window.showTextDocument(textDocument); | | 89 | + assert(vscode.window.activeTextEditor, 'No active editor'); | | 90 | + let position = new vscode.Position(20, 4); | | 91 | + let list = await vscode.commands.executeCommand<vscode.CompletionList>('vscode.executeCompletionItemProvider', textDocument.uri, position); | | 92 | + assert.notEqual(list.items.filter(item => item.label === 'a').length, 0, 'method a not found'); | | 93 | + | | 94 | + position = new vscode.Position(21, 4); | | 95 | + list = await vscode.commands.executeCommand<vscode.CompletionList>('vscode.executeCompletionItemProvider', textDocument.uri, position); | | 96 | + assert.notEqual(list.items.filter(item => item.label === 'b').length, 0, 'method b not found'); | | 97 | + }); | | 98 | + | | 99 | + test('class method types', async () => { | | 100 | + if (!await isPython3) { | | 101 | + return; | | 102 | + } | | 103 | + let textDocument = await vscode.workspace.openTextDocument(filePep526); | | 104 | + await vscode.window.showTextDocument(textDocument); | | 105 | + assert(vscode.window.activeTextEditor, 'No active editor'); | | 106 | + const position = new vscode.Position(21, 6); | | 107 | + const list = await vscode.commands.executeCommand<vscode.CompletionList>('vscode.executeCompletionItemProvider', textDocument.uri, position); | | 108 | + assert.notEqual(list.items.filter(item => item.label === 'bit_length').length, 0, 'bit_length not found'); | | 109 | + }); | 54 | 110 | }); |
Collapse file Copy file name to clipboardExpand all lines: src/test/definitions/code.test.ts +65-6Lines changed: 65 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 3 | 3 |
| 4 | 4 |
| 5 | 5 | // Place this right on top | 6 | | -import { initialize, PYTHON_PATH, closeActiveWindows } from '../initialize'; | | 6 | +import { initialize, PYTHON_PATH, closeActiveWindows, setPythonExecutable } from '../initialize'; | 7 | 7 | // The module 'assert' provides assertion methods from node | 8 | 8 | import * as assert from 'assert'; | 9 | 9 | import { EOL } from 'os'; | @@ -12,22 +12,29 @@ import { EOL } from 'os'; | 12 | 12 | import * as vscode from 'vscode'; | 13 | 13 | import * as path from 'path'; | 14 | 14 | import * as settings from '../../client/common/configSettings'; | | 15 | +import { execPythonFile } from '../../client/common/utils'; | | 16 | +import { createDeferred } from '../../client/common/helpers'; | 15 | 17 |
| 16 | 18 | let pythonSettings = settings.PythonSettings.getInstance(); | | 19 | +let disposable: vscode.Disposable; | 17 | 20 | let autoCompPath = path.join(__dirname, '..', '..', '..', 'src', 'test', 'pythonFiles', 'definition'); | 18 | 21 | const fileOne = path.join(autoCompPath, 'one.py'); | 19 | 22 | const fileTwo = path.join(autoCompPath, 'two.py'); | 20 | 23 | const fileThree = path.join(autoCompPath, 'three.py'); | 21 | 24 | const fileDecorator = path.join(autoCompPath, 'decorators.py'); | | 25 | +const fileAwait = path.join(autoCompPath, 'await.test.py'); | 22 | 26 | const fileEncoding = path.join(autoCompPath, 'four.py'); | 23 | 27 | const fileEncodingUsed = path.join(autoCompPath, 'five.py'); | 24 | 28 |
| | 29 | + | 25 | 30 | suite('Code Definition', () => { | 26 | | - suiteSetup(done => { | 27 | | - initialize().then(() => { | 28 | | - pythonSettings.pythonPath = PYTHON_PATH; | 29 | | - done(); | 30 | | - }, done); | | 31 | + const isPython3Deferred = createDeferred<boolean>(); | | 32 | + const isPython3 = isPython3Deferred.promise; | | 33 | + suiteSetup(async () => { | | 34 | + disposable = setPythonExecutable(pythonSettings); | | 35 | + await initialize(); | | 36 | + let version = await execPythonFile(pythonSettings.pythonPath, ['--version'], __dirname, true); | | 37 | + isPython3Deferred.resolve(version.indexOf('3.') >= 0); | 31 | 38 | }); | 32 | 39 |
| 33 | 40 | suiteTeardown(done => { | @@ -50,6 +57,7 @@ suite('Code Definition', () => { | 50 | 57 | return vscode.commands.executeCommand<vscode.Location[]>('vscode.executeDefinitionProvider', textDocument.uri, position); | 51 | 58 | }).then(def => { | 52 | 59 | assert.equal(def.length, 1, 'Definition length is incorrect'); | | 60 | + assert.equal(def[0].uri.fsPath, fileOne, 'Incorrect file'); | 53 | 61 | assert.equal(`${def[0].range.start.line},${def[0].range.start.character}`, '17,4', 'Start position is incorrect'); | 54 | 62 | assert.equal(`${def[0].range.end.line},${def[0].range.end.character}`, '21,11', 'End position is incorrect'); | 55 | 63 | }).then(done, done); | @@ -68,6 +76,7 @@ suite('Code Definition', () => { | 68 | 76 | return vscode.commands.executeCommand<vscode.Location[]>('vscode.executeDefinitionProvider', textDocument.uri, position); | 69 | 77 | }).then(def => { | 70 | 78 | assert.equal(def.length, 1, 'Definition length is incorrect'); | | 79 | + assert.equal(def[0].uri.fsPath, fileOne, 'Incorrect file'); | 71 | 80 | assert.equal(`${def[0].range.start.line},${def[0].range.start.character}`, '32,0', 'Start position is incorrect'); | 72 | 81 | assert.equal(`${def[0].range.end.line},${def[0].range.end.character}`, '33,21', 'End position is incorrect'); | 73 | 82 | }).then(done, done); | @@ -79,10 +88,32 @@ suite('Code Definition', () => { | 79 | 88 | const position = new vscode.Position(7, 2); | 80 | 89 | const def = await vscode.commands.executeCommand<vscode.Location[]>('vscode.executeDefinitionProvider', textDocument.uri, position); | 81 | 90 | assert.equal(def.length, 1, 'Definition length is incorrect'); | | 91 | + assert.equal(def[0].uri.fsPath, fileDecorator, 'Incorrect file'); | 82 | 92 | assert.equal(`${def[0].range.start.line},${def[0].range.start.character}`, '4,0', 'Start position is incorrect'); | 83 | 93 | assert.equal(`${def[0].range.end.line},${def[0].range.end.character}`, '5,22', 'End position is incorrect'); | 84 | 94 | }); | 85 | 95 |
| | 96 | + test('Go to function with decorator (jit)', async () => { | | 97 | + const textDocument = await vscode.workspace.openTextDocument(fileDecorator); | | 98 | + await vscode.window.showTextDocument(textDocument); | | 99 | + const position = new vscode.Position(27, 2); | | 100 | + const def = await vscode.commands.executeCommand<vscode.Location[]>('vscode.executeDefinitionProvider', textDocument.uri, position); | | 101 | + assert.equal(def.length, 1, 'Definition length is incorrect'); | | 102 | + assert.equal(def[0].uri.fsPath, fileDecorator, 'Incorrect file'); | | 103 | + assert.equal(`${def[0].range.start.line},${def[0].range.start.character}`, '19,0', 'Start position is incorrect'); | | 104 | + assert.equal(`${def[0].range.end.line},${def[0].range.end.character}`, '26,42', 'End position is incorrect'); | | 105 | + }); | | 106 | + | | 107 | + test('Go to function with decorator (fabric)', async () => { | | 108 | + const textDocument = await vscode.workspace.openTextDocument(fileDecorator); | | 109 | + await vscode.window.showTextDocument(textDocument); | | 110 | + const position = new vscode.Position(13, 2); | | 111 | + const def = await vscode.commands.executeCommand<vscode.Location[]>('vscode.executeDefinitionProvider', textDocument.uri, position); | | 112 | + assert.equal(def.length, 1, 'Definition length is incorrect'); | | 113 | + assert.equal(`${def[0].range.start.line},${def[0].range.start.character}`, '19,0', 'Start position is incorrect'); | | 114 | + assert.equal(`${def[0].range.end.line},${def[0].range.end.character}`, '26,42', 'End position is incorrect'); | | 115 | + }); | | 116 | + | 86 | 117 | test('Go to function decorator', async () => { | 87 | 118 | const textDocument = await vscode.workspace.openTextDocument(fileDecorator); | 88 | 119 | await vscode.window.showTextDocument(textDocument); | @@ -93,6 +124,34 @@ suite('Code Definition', () => { | 93 | 124 | assert.equal(`${def[0].range.end.line},${def[0].range.end.character}`, '1,12', 'End position is incorrect'); | 94 | 125 | }); | 95 | 126 |
| | 127 | + test('Go to async method', async () => { | | 128 | + if (!await isPython3) { | | 129 | + return; | | 130 | + } | | 131 | + const textDocument = await vscode.workspace.openTextDocument(fileAwait); | | 132 | + await vscode.window.showTextDocument(textDocument); | | 133 | + const position = new vscode.Position(10, 22); | | 134 | + const def = await vscode.commands.executeCommand<vscode.Location[]>('vscode.executeDefinitionProvider', textDocument.uri, position); | | 135 | + assert.equal(def.length, 1, 'Definition length is incorrect (currently not working)'); | | 136 | + assert.equal(def[0].uri.fsPath, fileAwait, 'Wrong file (currently not working)'); | | 137 | + assert.equal(`${def[0].range.start.line},${def[0].range.start.character}`, '6,10', 'Start position is incorrect (currently not working)'); | | 138 | + assert.equal(`${def[0].range.end.line},${def[0].range.end.character}`, '1,12', 'End position is incorrect (currently not working)'); | | 139 | + }); | | 140 | + | | 141 | + test('Go to async function', async () => { | | 142 | + if (!await isPython3) { | | 143 | + return; | | 144 | + } | | 145 | + const textDocument = await vscode.workspace.openTextDocument(fileAwait); | | 146 | + await vscode.window.showTextDocument(textDocument); | | 147 | + const position = new vscode.Position(18, 12); | | 148 | + const def = await vscode.commands.executeCommand<vscode.Location[]>('vscode.executeDefinitionProvider', textDocument.uri, position); | | 149 | + assert.equal(def.length, 1, 'Definition length is incorrect (currently not working)'); | | 150 | + assert.equal(def[0].uri.fsPath, fileAwait, 'Wrong file (currently not working)'); | | 151 | + assert.equal(`${def[0].range.start.line},${def[0].range.start.character}`, '6,10', 'Start position is incorrect (currently not working)'); | | 152 | + assert.equal(`${def[0].range.end.line},${def[0].range.end.character}`, '1,12', 'End position is incorrect (currently not working)'); | | 153 | + }); | | 154 | + | 96 | 155 | test('Across files', done => { | 97 | 156 | let textEditor: vscode.TextEditor; | 98 | 157 | let textDocument: vscode.TextDocument; | |
|