use of org.python.pydev.core.docutils.PySelection.DocstringInfo in project Pydev by fabioz.
the class AssistDocString method getProps.
/**
* @see org.python.pydev.editor.correctionassist.IAssistProps#getProps(org.python.pydev.core.docutils.PySelection,
* org.python.pydev.shared_ui.ImageCache)
*/
@Override
public List<ICompletionProposalHandle> getProps(PySelection ps, IImageCache imageCache, File f, IPythonNature nature, IPyEdit edit, int offset) throws BadLocationException {
ArrayList<ICompletionProposalHandle> l = new ArrayList<>();
Tuple<List<String>, Integer> tuple = ps.getInsideParentesisToks(false);
if (tuple == null) {
if (ps.isInClassLine()) {
tuple = new Tuple<List<String>, Integer>(new ArrayList<String>(), offset);
} else {
return l;
}
}
List<String> params = tuple.o1;
int lineOfOffset = ps.getLineOfOffset(tuple.o2);
// Calculate only the initial part of the docstring here (everything else should be lazily computed on apply).
String initial = PySelection.getIndentationFromLine(ps.getCursorLineContents());
String delimiter = PyAction.getDelimiter(ps.getDoc());
String indentation = edit != null ? edit.getIndentPrefs().getIndentationString() : DefaultIndentPrefs.get(nature).getIndentationString();
String delimiterAndIndent = delimiter + initial + indentation;
FastStringBuffer buf = new FastStringBuffer();
String docStringMarker = DocstringsPrefPage.getDocstringMarker();
buf.append(delimiterAndIndent + docStringMarker);
buf.append(delimiterAndIndent);
int newOffset = buf.length();
int offsetPosToAdd = ps.getEndLineOffset(lineOfOffset);
// may be null (testing)
IImageHandle image = null;
if (imageCache != null) {
image = imageCache.get(UIConstants.ASSIST_DOCSTRING);
}
final boolean inFunctionLine = ps.isInFunctionLine(true);
DocstringInfo docstringFromFunction = null;
if (inFunctionLine) {
int currLine = ps.getLineOfOffset();
docstringFromFunction = ps.getDocstringFromLine(currLine + 1);
}
final DocstringInfo finalDocstringFromFunction = docstringFromFunction;
String preferredDocstringStyle = AssistDocString.this.docStringStyle;
if (preferredDocstringStyle == null) {
preferredDocstringStyle = DocstringsPrefPage.getPreferredDocstringStyle();
}
final String preferredDocstringStyle2 = preferredDocstringStyle;
if (preferredDocstringStyle.equals(DocstringsPrefPage.DOCSTRINGSTYLE_GOOGLE)) {
buf.append("Args:");
}
l.add(CompletionProposalFactory.get().createAssistDocstringCompletionProposal("", offsetPosToAdd, 0, newOffset, image, finalDocstringFromFunction != null ? "Update docstring" : "Make docstring", null, null, IPyCompletionProposal.PRIORITY_DEFAULT, null, initial, delimiter, docStringMarker, delimiterAndIndent, preferredDocstringStyle2, inFunctionLine, finalDocstringFromFunction, indentation, buf, params));
return l;
}
use of org.python.pydev.core.docutils.PySelection.DocstringInfo in project Pydev by fabioz.
the class PySelectionTest method testGetDocstringFromLine.
public void testGetDocstringFromLine() throws BadLocationException {
doc = new Document("def m1():\n 'docstring'");
ps = new PySelection(doc);
DocstringInfo docstringFromLine = ps.getDocstringFromLine(1);
assertEquals("DocstringInfo [startLiteralOffset=14, endLiteralOffset=25, string='docstring']", docstringFromLine.toString());
assertEquals(11, docstringFromLine.getLength());
assertEquals("'docstring'", doc.get(docstringFromLine.startLiteralOffset, docstringFromLine.getLength()));
}
use of org.python.pydev.core.docutils.PySelection.DocstringInfo in project Pydev by fabioz.
the class PySelectionTest method testGetDocstringFromLineInvalid.
public void testGetDocstringFromLineInvalid() {
doc = new Document("def m1():\n '''docstring\n ''");
ps = new PySelection(doc);
DocstringInfo docstringFromLine = ps.getDocstringFromLine(1);
assertNull(docstringFromLine);
}
use of org.python.pydev.core.docutils.PySelection.DocstringInfo in project Pydev by fabioz.
the class PySelectionTest method testGetDocstringFromLine2.
public void testGetDocstringFromLine2() throws BadLocationException {
doc = new Document("def m1():\n '''docstring\n '''");
ps = new PySelection(doc);
DocstringInfo docstringFromLine = ps.getDocstringFromLine(1);
assertEquals("DocstringInfo [startLiteralOffset=14, endLiteralOffset=34, string='''docstring\n" + " ''']", docstringFromLine.toString());
assertEquals("'''docstring\n '''", doc.get(docstringFromLine.startLiteralOffset, docstringFromLine.getLength()));
}
Aggregations