-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Provide full signature help with highlighted parameter #416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 31 commits
7675901
eb42669
2756974
c2c1ced
a108c96
14864a5
0ed51d6
51b544c
3cd11e6
82e0ad1
9295c1a
06eb1a5
e9db8e0
d12ca03
d8ab041
db75cd0
9ab2c47
d587485
1da5e0a
7668cee
1ac4932
2aa5a6c
5db31bd
560d2af
c71024d
31aa087
593ae05
e6d69bb
b5a23d3
cd200f7
7c33228
c4a6b90
f85b848
37c210b
61a5650
a10305e
11aaae2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{ | ||
"python.command.python.sortImports.title": "Отсортировать Imports", | ||
"python.command.python.startREPL.title": "Открыть REPL", | ||
"python.command.python.buildWorkspaceSymbols.title": "Собрать символы рабочего пространства", | ||
"python.command.python.runtests.title": "Запустить все тесты", | ||
"python.command.python.debugtests.title": "Запустить все тесты под отладчиком", | ||
"python.command.python.execInTerminal.title": "Выполнить файл в консоли", | ||
"python.command.python.setInterpreter.title": "Выбрать интерпретатор", | ||
"python.command.python.updateSparkLibrary.title": "Обновить библиотеки PySpark", | ||
"python.command.python.refactorExtractVariable.title": "Извлечь в переменную", | ||
"python.command.python.refactorExtractMethod.title": "Извлечь в метод", | ||
"python.command.python.viewTestOutput.title": "Показать вывод теста", | ||
"python.command.python.selectAndRunTestMethod.title": "Запусть тестовый метод...", | ||
"python.command.python.selectAndDebugTestMethod.title": "Отладить тестовый метод...", | ||
"python.command.python.selectAndRunTestFile.title": "Запустить тестовый файл...", | ||
"python.command.python.runCurrentTestFile.title": "Запустить текущий тестовый файл", | ||
"python.command.python.runFailedTests.title": "Запустить непрошедшие тесты", | ||
"python.command.python.execSelectionInTerminal.title": "Выполнить выбранный текст или текущую строку в консоли", | ||
"python.command.python.execSelectionInDjangoShell.title": "Выполнить выбранный текст или текущую строку в оболочке Django", | ||
"python.command.jupyter.runSelectionLine.title": "Выполнить выбранный текст или текущую строку", | ||
"python.command.jupyter.execCurrentCell.title": "Выполнить ячейку", | ||
"python.command.jupyter.execCurrentCellAndAdvance.title": "Выполнить ячейку и перейти к следующей", | ||
"python.command.jupyter.gotToPreviousCell.title": "Перейти к предыдущей ячейке", | ||
"python.command.jupyter.gotToNextCell.title": "Перейти к следующей ячейке", | ||
"python.command.python.goToPythonObject.title": "Перейти к объекту Python", | ||
"python.snippet.launch.standard.label": "Python", | ||
"python.snippet.launch.standard.description": "Отладить программу Python со стандартным выводом", | ||
"python.snippet.launch.pyspark.label": "Python: PySpark", | ||
"python.snippet.launch.pyspark.description": "Отладка PySpark", | ||
"python.snippet.launch.module.label": "Python: Модуль", | ||
"python.snippet.launch.module.description": "Отладка модуля", | ||
"python.snippet.launch.terminal.label": "Python: Интегрированная консоль", | ||
"python.snippet.launch.terminal.description": "Отладка программы Python в интегрированной консоли", | ||
"python.snippet.launch.externalTerminal.label": "Python: Внешний терминал", | ||
"python.snippet.launch.externalTerminal.description": "Отладка программы Python во внешней консоли", | ||
"python.snippet.launch.django.label": "Python: Django", | ||
"python.snippet.launch.django.description": "Отладка приложения Django", | ||
"python.snippet.launch.flask.label": "Python: Flask (0.11.x или новее)", | ||
"python.snippet.launch.flask.description": "Отладка приложения Flask", | ||
"python.snippet.launch.flaskOld.label": "Python: Flask (0.10.x или старее)", | ||
"python.snippet.launch.flaskOld.description": "Отладка приложения Flask (старый стиль)", | ||
"python.snippet.launch.pyramid.label": "Python: Приложение Pyramid", | ||
"python.snippet.launch.pyramid.description": "Отладка приложения Pyramid", | ||
"python.snippet.launch.watson.label": "Python: Приложение Watson", | ||
"python.snippet.launch.watson.description": "Отладка приложения Watson", | ||
"python.snippet.launch.attach.label": "Python: Подключить отладчик", | ||
"python.snippet.launch.attach.description": "Подключить отладчик для удаленной отладки", | ||
"python.snippet.launch.scrapy.label": "Python: Scrapy", | ||
"python.snippet.launch.scrapy.description": "Scrapy в интегрированной консоли" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
'use strict'; | ||
|
||
import { EOL } from 'os'; | ||
import * as vscode from 'vscode'; | ||
import { CancellationToken, Position, SignatureHelp, TextDocument } from 'vscode'; | ||
import { JediFactory } from '../languageServices/jediProxyFactory'; | ||
|
@@ -55,8 +56,13 @@ export class PythonSignatureProvider implements vscode.SignatureHelpProvider { | |
signature.activeParameter = def.paramindex; | ||
// Don't display the documentation, as vs code doesn't format the docmentation. | ||
// i.e. line feeds are not respected, long content is stripped. | ||
const docLines = def.docstring.splitLines(); | ||
const label = docLines[0].trim(); | ||
const documentation = docLines.length > 1 ? docLines.filter((line, index) => index > 0).join(EOL) : ''; | ||
|
||
const sig = <vscode.SignatureInformation>{ | ||
label: def.description, | ||
label: label, | ||
documentation: documentation, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead of |
||
parameters: [] | ||
}; | ||
sig.parameters = def.params.map(arg => { | ||
|
@@ -65,7 +71,7 @@ export class PythonSignatureProvider implements vscode.SignatureHelpProvider { | |
} | ||
return <vscode.ParameterInformation>{ | ||
documentation: arg.docstring.length > 0 ? arg.docstring : arg.description, | ||
label: arg.description.length > 0 ? arg.description : arg.name | ||
label: arg.name | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lol, I hang my head in shame for this simple bug. 😞 . Nothing to do here. |
||
}; | ||
}); | ||
signature.signatures.push(sig); | ||
|
@@ -85,7 +91,7 @@ export class PythonSignatureProvider implements vscode.SignatureHelpProvider { | |
source: document.getText() | ||
}; | ||
return this.jediFactory.getJediProxyHandler<proxy.IArgumentsResult>(document.uri).sendCommand(cmd, token).then(data => { | ||
return PythonSignatureProvider.parseData(data); | ||
return data ? PythonSignatureProvider.parseData(data) : undefined; | ||
}); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class Person: | ||
def __init__(self, name, age = 23): | ||
self.name = name | ||
self.age = age | ||
|
||
p1 = Person('Bob', ) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pow(c, 1, |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
'use strict'; | ||
|
||
import * as assert from 'assert'; | ||
import * as path from 'path'; | ||
import * as vscode from 'vscode'; | ||
import { closeActiveWindows, initialize, initializeTest } from '../initialize'; | ||
|
||
const autoCompPath = path.join(__dirname, '..', '..', '..', 'src', 'test', 'pythonFiles', 'signature'); | ||
const fileOne = path.join(autoCompPath, 'one.py'); | ||
const fileTwo = path.join(autoCompPath, 'two.py'); | ||
|
||
class SignatureHelpResult { | ||
constructor( | ||
public line: number, | ||
public index: number, | ||
public signaturesCount: number, | ||
public activeParameter: number, | ||
public parameterName: string | null) { } | ||
} | ||
|
||
// tslint:disable-next-line:max-func-body-length | ||
suite('Signatures', () => { | ||
suiteSetup(async () => { | ||
await initialize(); | ||
}); | ||
setup(initializeTest); | ||
suiteTeardown(closeActiveWindows); | ||
teardown(closeActiveWindows); | ||
|
||
test('For ctor', async () => { | ||
const expected = [ | ||
new SignatureHelpResult(5, 11, 0, 0, null), | ||
new SignatureHelpResult(5, 12, 1, 0, 'name'), | ||
new SignatureHelpResult(5, 13, 1, 0, 'name'), | ||
new SignatureHelpResult(5, 14, 1, 0, 'name'), | ||
new SignatureHelpResult(5, 15, 1, 0, 'name'), | ||
new SignatureHelpResult(5, 16, 1, 0, 'name'), | ||
new SignatureHelpResult(5, 17, 1, 0, 'name'), | ||
new SignatureHelpResult(5, 18, 1, 1, 'age'), | ||
new SignatureHelpResult(5, 19, 1, 1, 'age'), | ||
new SignatureHelpResult(5, 20, 0, 0, null) | ||
]; | ||
|
||
const document = await openDocument(fileOne); | ||
for (const e of expected) { | ||
await checkSignature(e, document!.uri); | ||
} | ||
}); | ||
|
||
test('For intrinsic', async () => { | ||
const expected = [ | ||
new SignatureHelpResult(0, 0, 0, 0, null), | ||
new SignatureHelpResult(0, 1, 0, 0, null), | ||
new SignatureHelpResult(0, 2, 0, 0, null), | ||
new SignatureHelpResult(0, 3, 0, 0, null), | ||
new SignatureHelpResult(0, 4, 1, 0, 'x'), | ||
new SignatureHelpResult(0, 5, 1, 0, 'x'), | ||
new SignatureHelpResult(0, 6, 1, 1, 'y'), | ||
new SignatureHelpResult(0, 7, 1, 1, 'y'), | ||
new SignatureHelpResult(0, 8, 1, 1, 'y'), | ||
new SignatureHelpResult(0, 9, 1, 2, 'z'), | ||
new SignatureHelpResult(0, 10, 1, 2, 'z'), | ||
new SignatureHelpResult(1, 0, 1, 2, 'z') | ||
]; | ||
|
||
const document = await openDocument(fileTwo); | ||
for (const e of expected) { | ||
await checkSignature(e, document!.uri); | ||
} | ||
}); | ||
}); | ||
|
||
async function openDocument(documentPath: string): Promise<vscode.TextDocument | undefined> { | ||
const document = await vscode.workspace.openTextDocument(documentPath); | ||
await vscode.window.showTextDocument(document!); | ||
return document; | ||
} | ||
|
||
async function checkSignature(expected: SignatureHelpResult, uri: vscode.Uri) { | ||
const position = new vscode.Position(expected.line, expected.index); | ||
const actual = await vscode.commands.executeCommand<vscode.SignatureHelp>('vscode.executeSignatureHelpProvider', uri, position); | ||
assert.equal(actual!.signatures.length, expected.signaturesCount); | ||
if (expected.signaturesCount > 0) { | ||
assert.equal(actual!.activeParameter, expected.activeParameter); | ||
const parameter = actual!.signatures[0].parameters[expected.activeParameter]; | ||
assert.equal(parameter.label, expected.parameterName); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could improve the code as follows: