Skip to content

Commit

Permalink
Assist docstring fix: properly update docstring when signature spans …
Browse files Browse the repository at this point in the history
…multiple lines.
  • Loading branch information
fabioz committed Oct 13, 2024
1 parent 633aca2 commit 5edd8b4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ public List<ICompletionProposalHandle> getProps(PySelection ps, IImageCache imag
}
}
List<String> params = tuple.contents;
int lineOfOffset = ps.getLineOfOffset(tuple.closeParenthesisOffset);

// Calculate only the initial part of the docstring here (everything else should be lazily computed on apply).
String initial = PySelection.getIndentationFromLine(ps.getCursorLineContents());
Expand All @@ -90,6 +89,7 @@ public List<ICompletionProposalHandle> getProps(PySelection ps, IImageCache imag
buf.append(delimiterAndIndent);

int newOffset = buf.length();
int lineOfOffset = ps.getLineOfOffset(tuple.closeParenthesisOffset);
int offsetPosToAdd = ps.getEndLineOffset(lineOfOffset);

IImageHandle image = null; //may be null (testing)
Expand All @@ -99,8 +99,7 @@ public List<ICompletionProposalHandle> getProps(PySelection ps, IImageCache imag
final boolean inFunctionLine = ps.isInFunctionLine(true);
DocstringInfo docstringFromFunction = null;
if (inFunctionLine) {
int currLine = ps.getLineOfOffset();
docstringFromFunction = ps.getDocstringFromLine(currLine + 1);
docstringFromFunction = ps.getDocstringFromLine(lineOfOffset + 1);
}
final DocstringInfo finalDocstringFromFunction = docstringFromFunction;
String preferredDocstringStyle = AssistDocString.this.docStringStyle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,40 @@ public void testApplyGoogle1() throws Exception {

public void testApplyGoogle2() throws Exception {
String expected;
expected = " def foo(self): #comment\r\n" +
" '''\r\n" +
" \r\n" +
" '''";
expected = """
def foo(self): #comment
'''
....
'''\
""".replace("....", " ");
checkGoogle(expected, " def foo(self): #comment", 1);
}

public void testUpdateDocstringGoogleRequest() throws Exception {
String expected;
expected = """
def foo(
self,
a,
b):
'''
Args:
a:
b:
'''
""";
checkGoogle(expected, """
def foo(
self,
a,
b):
'''
Args:
a:
'''
""", 1);
}

public void testApply() throws Exception {
String expected;
expected = "def foo(a): #comment\r\n" +
Expand Down

0 comments on commit 5edd8b4

Please sign in to comment.