mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 03:21:12 +07:00
fixed PY-5029 Editable auto stub string
This commit is contained in:
@@ -41,6 +41,8 @@ public class PyCodeInsightSettings implements PersistentStateComponent<PyCodeIns
|
||||
public boolean INSERT_BACKSLASH_ON_WRAP = true;
|
||||
public boolean INSERT_SELF_FOR_METHODS = true;
|
||||
|
||||
public boolean INSERT_TYPE_DOCSTUB = false;
|
||||
|
||||
public PyCodeInsightSettings getState() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,8 @@ import com.intellij.openapi.options.UnnamedConfigurable;
|
||||
public class PySpecificSmartKeysOptions extends BeanConfigurable<PyCodeInsightSettings> implements UnnamedConfigurable {
|
||||
public PySpecificSmartKeysOptions() {
|
||||
super(PyCodeInsightSettings.getInstance());
|
||||
checkBox("INSERT_BACKSLASH_ON_WRAP", "Insert \\ when pressing Enter inside a statement");
|
||||
checkBox("INSERT_BACKSLASH_ON_WRAP", "Insert backslash when pressing Enter inside a statement");
|
||||
checkBox("INSERT_SELF_FOR_METHODS", "Insert 'self' when defining a method");
|
||||
checkBox("INSERT_TYPE_DOCSTUB", "Insert \"type\" and \"rtype\" to the documentation comment stub");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.Function;
|
||||
import com.jetbrains.python.PyNames;
|
||||
import com.jetbrains.python.codeInsight.PyCodeInsightSettings;
|
||||
import com.jetbrains.python.console.PydevConsoleRunner;
|
||||
import com.jetbrains.python.console.PydevDocumentationProvider;
|
||||
import com.jetbrains.python.psi.*;
|
||||
@@ -469,6 +470,13 @@ public class PythonDocumentationProvider extends AbstractDocumentationProvider i
|
||||
builder.append(p.getName());
|
||||
builder.append(": ");
|
||||
builder.append(offset);
|
||||
if (PyCodeInsightSettings.getInstance().INSERT_TYPE_DOCSTUB) {
|
||||
builder.append(prefix);
|
||||
builder.append("type ");
|
||||
builder.append(p.getName());
|
||||
builder.append(": ");
|
||||
builder.append(offset);
|
||||
}
|
||||
}
|
||||
if (checkReturn) {
|
||||
RaiseVisitor visitor = new RaiseVisitor();
|
||||
@@ -476,13 +484,21 @@ public class PythonDocumentationProvider extends AbstractDocumentationProvider i
|
||||
if (statementList != null) {
|
||||
statementList.accept(visitor);
|
||||
}
|
||||
if (visitor.myHasReturn)
|
||||
if (visitor.myHasReturn) {
|
||||
builder.append(prefix).append("return:").append(offset);
|
||||
if (PyCodeInsightSettings.getInstance().INSERT_TYPE_DOCSTUB) {
|
||||
builder.append(prefix).append("rtype:").append(offset);
|
||||
}
|
||||
}
|
||||
if (visitor.myHasRaise)
|
||||
builder.append(prefix).append("raise:").append(offset);
|
||||
}
|
||||
else
|
||||
else {
|
||||
builder.append(prefix).append("return:").append(offset);
|
||||
if (PyCodeInsightSettings.getInstance().INSERT_TYPE_DOCSTUB) {
|
||||
builder.append(prefix).append("rtype:").append(offset);
|
||||
}
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
|
||||
9
python/testData/codeInsight/smartEnter/docTypeRType.py
Normal file
9
python/testData/codeInsight/smartEnter/docTypeRType.py
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
def foo(a):
|
||||
"""<caret>
|
||||
pass
|
||||
|
||||
def foo1():
|
||||
"""
|
||||
:return :
|
||||
"""
|
||||
15
python/testData/codeInsight/smartEnter/docTypeRType_after.py
Normal file
15
python/testData/codeInsight/smartEnter/docTypeRType_after.py
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
def foo(a):
|
||||
"""
|
||||
<caret>
|
||||
@param a:
|
||||
@type a:
|
||||
@return:
|
||||
@rtype:
|
||||
"""
|
||||
pass
|
||||
|
||||
def foo1():
|
||||
"""
|
||||
:return :
|
||||
"""
|
||||
@@ -7,6 +7,7 @@ import com.intellij.lang.Language;
|
||||
import com.intellij.openapi.application.Result;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.jetbrains.python.codeInsight.PyCodeInsightSettings;
|
||||
import com.jetbrains.python.documentation.DocStringFormat;
|
||||
import com.jetbrains.python.documentation.PyDocumentationSettings;
|
||||
import com.jetbrains.python.fixtures.PyTestCase;
|
||||
@@ -106,6 +107,7 @@ public class PySmartEnterTest extends PyTestCase {
|
||||
|
||||
public void testDocRest() {
|
||||
CodeInsightSettings codeInsightSettings = CodeInsightSettings.getInstance();
|
||||
boolean oldStubOnEnter = codeInsightSettings.JAVADOC_STUB_ON_ENTER;
|
||||
codeInsightSettings.JAVADOC_STUB_ON_ENTER = true;
|
||||
PyDocumentationSettings documentationSettings = PyDocumentationSettings.getInstance(myFixture.getProject());
|
||||
documentationSettings.setFormat(DocStringFormat.REST);
|
||||
@@ -114,11 +116,13 @@ public class PySmartEnterTest extends PyTestCase {
|
||||
}
|
||||
finally {
|
||||
documentationSettings.setFormat(DocStringFormat.PLAIN);
|
||||
codeInsightSettings.JAVADOC_STUB_ON_ENTER = oldStubOnEnter;
|
||||
}
|
||||
}
|
||||
|
||||
public void testDocEpytext() {
|
||||
CodeInsightSettings codeInsightSettings = CodeInsightSettings.getInstance();
|
||||
boolean oldStubOnEnter = codeInsightSettings.JAVADOC_STUB_ON_ENTER;
|
||||
codeInsightSettings.JAVADOC_STUB_ON_ENTER = true;
|
||||
PyDocumentationSettings documentationSettings = PyDocumentationSettings.getInstance(myFixture.getProject());
|
||||
documentationSettings.setFormat(DocStringFormat.EPYTEXT);
|
||||
@@ -127,6 +131,27 @@ public class PySmartEnterTest extends PyTestCase {
|
||||
}
|
||||
finally {
|
||||
documentationSettings.setFormat(DocStringFormat.PLAIN);
|
||||
codeInsightSettings.JAVADOC_STUB_ON_ENTER = oldStubOnEnter;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void testDocTypeRtype() {
|
||||
CodeInsightSettings codeInsightSettings = CodeInsightSettings.getInstance();
|
||||
boolean oldStubOnEnter = codeInsightSettings.JAVADOC_STUB_ON_ENTER;
|
||||
codeInsightSettings.JAVADOC_STUB_ON_ENTER = true;
|
||||
PyCodeInsightSettings pyCodeInsightSettings = PyCodeInsightSettings.getInstance();
|
||||
boolean oldInsertType = pyCodeInsightSettings.INSERT_TYPE_DOCSTUB;
|
||||
pyCodeInsightSettings.INSERT_TYPE_DOCSTUB = true;
|
||||
PyDocumentationSettings documentationSettings = PyDocumentationSettings.getInstance(myFixture.getProject());
|
||||
documentationSettings.setFormat(DocStringFormat.EPYTEXT);
|
||||
try {
|
||||
doTest();
|
||||
}
|
||||
finally {
|
||||
documentationSettings.setFormat(DocStringFormat.PLAIN);
|
||||
codeInsightSettings.JAVADOC_STUB_ON_ENTER = oldStubOnEnter;
|
||||
pyCodeInsightSettings.INSERT_TYPE_DOCSTUB = oldInsertType;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user