Skip to content

Commit d2ef26c

Browse files
authored
Merge pull request #734 from jupyter-lsp/signature-details
Fix signature blur and fix formatting when no arguments are present
2 parents ed88a08 + ba31cdc commit d2ef26c

File tree

4 files changed

+102
-8
lines changed

4 files changed

+102
-8
lines changed

atest/05_Features/Signature.robot

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ Test Setup Setup Notebook Python Signature.ipynb
66
Test Teardown Clean Up After Working With File Signature.ipynb
77

88
*** Variables ***
9+
${SIGNATURE PLUGIN ID} @krassowski/jupyterlab-lsp:signature
910
${SIGNATURE_BOX} css:.lsp-signature-help
1011
${SIGNATURE_HIGHLIGHTED_ARG} css:.lsp-signature-help mark
12+
${SIGNATURE_DETAILS_CSS} .lsp-signature-help details
13+
${SIGNATURE_DETAILS} css:${SIGNATURE_DETAILS_CSS}
1114

1215
*** Test Cases ***
1316
Triggers Signature Help After A Keystroke
@@ -51,3 +54,27 @@ Invalidates On Cell Change
5154
Wait Until Keyword Succeeds 20x 0.5s Page Should Contain Element ${SIGNATURE_BOX}
5255
Enter Cell Editor 2
5356
Wait Until Keyword Succeeds 20x 0.5s Page Should Not Contain Element ${SIGNATURE_BOX}
57+
58+
Details Should Expand On Click
59+
Configure JupyterLab Plugin {"maxLines": 4} plugin id=${SIGNATURE PLUGIN ID}
60+
Enter Cell Editor 3 line=11
61+
Press Keys None (
62+
Wait Until Keyword Succeeds 20x 0.5s Page Should Contain Element ${SIGNATURE_BOX}
63+
Wait Until Keyword Succeeds 10x 0.5s Element Should Contain ${SIGNATURE_BOX} Short description.
64+
Page Should Contain Element ${SIGNATURE_DETAILS}
65+
Details Should Be Collapsed ${SIGNATURE_DETAILS_CSS}
66+
Click Element ${SIGNATURE_DETAILS}
67+
Details Should Be Expanded ${SIGNATURE_DETAILS_CSS}
68+
69+
*** Keywords ***
70+
71+
Details Should Be Expanded
72+
[Arguments] ${css_locator}
73+
${is_open} Execute JavaScript return document.querySelector('${css_locator}').open
74+
Should Be True ${is_open} == True
75+
76+
77+
Details Should Be Collapsed
78+
[Arguments] ${css_locator}
79+
${is_open} Execute JavaScript return document.querySelector('${css_locator}').open
80+
Should Be True ${is_open} == False

atest/examples/Signature.ipynb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,25 @@
2727
"source": [
2828
"list"
2929
]
30+
},
31+
{
32+
"cell_type": "code",
33+
"execution_count": null,
34+
"metadata": {},
35+
"outputs": [],
36+
"source": [
37+
"def with_long():\n",
38+
" \"\"\"Short description.\n",
39+
"\n",
40+
" This is a longer description.\n",
41+
" The longer description is spread across several lines.\n",
42+
" This is to see the details collapse.\n",
43+
" The number of lines needed depends on `maxLines` setting.\n",
44+
" \"\"\"\n",
45+
"\n",
46+
"\n",
47+
"with_long"
48+
]
3049
}
3150
],
3251
"metadata": {

packages/jupyterlab-lsp/src/features/signature.spec.ts

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ describe('Signature', () => {
7676
new BrowserConsole()
7777
);
7878
expect(text).to.be.equal(
79-
'str(<u>text</u>)\nCreate a new \\*string\\* object from the given object.\n'
79+
'str(<u>text</u>)\n\nCreate a new \\*string\\* object from the given object.\n'
8080
);
8181
});
8282

@@ -101,7 +101,7 @@ describe('Signature', () => {
101101
new BrowserConsole()
102102
);
103103
expect(text).to.be.equal(
104-
'str(<u>text</u>)\nCreate a new \\*string\\* object from the given object.\n'
104+
'str(<u>text</u>)\n\nCreate a new \\*string\\* object from the given object.\n'
105105
);
106106
});
107107

@@ -126,7 +126,54 @@ describe('Signature', () => {
126126
new BrowserConsole()
127127
);
128128
expect(text).to.be.equal(
129-
'str(<u>text</u>)\nCreate a new *string* object from the given object.'
129+
'str(<u>text</u>)\n\nCreate a new *string* object from the given object.'
130+
);
131+
});
132+
133+
it('renders plaintext with details and paramaters', async () => {
134+
let text = signatureToMarkdown(
135+
{
136+
label: 'str(text)',
137+
documentation: {
138+
value: 'line 1\n\nline 2\nline 3\nline 4\nline 5',
139+
kind: 'plaintext'
140+
},
141+
parameters: [
142+
{
143+
label: 'text',
144+
documentation: undefined
145+
}
146+
],
147+
activeParameter: 0
148+
},
149+
'python',
150+
MockHighlighter,
151+
new BrowserConsole(),
152+
undefined,
153+
4
154+
);
155+
expect(text).to.be.equal(
156+
'str(<u>text</u>)\n\nline 1\n<details>\nline 2\nline 3\nline 4\nline 5\n</details>'
157+
);
158+
});
159+
160+
it('renders plaintext with details and no parameters', async () => {
161+
let text = signatureToMarkdown(
162+
{
163+
label: 'str()',
164+
documentation: {
165+
value: 'line 1\n\nline 2\nline 3\nline 4\nline 5',
166+
kind: 'plaintext'
167+
}
168+
},
169+
'python',
170+
MockHighlighter,
171+
new BrowserConsole(),
172+
undefined,
173+
4
174+
);
175+
expect(text).to.be.equal(
176+
'```python\nstr()\n```\n\nline 1\n<details>\nline 2\nline 3\nline 4\nline 5\n</details>'
130177
);
131178
});
132179
});

packages/jupyterlab-lsp/src/features/signature.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ export function signatureToMarkdown(
104104
}
105105
let details = '';
106106
if (item.documentation) {
107-
details += '\n';
108107
if (
109108
typeof item.documentation === 'string' ||
110109
item.documentation.kind === 'plaintext'
@@ -123,7 +122,7 @@ export function signatureToMarkdown(
123122
}
124123
} else {
125124
if (item.documentation.kind !== 'markdown') {
126-
console.warn('Unknown MarkupContent kind:', item.documentation.kind);
125+
logger.warn('Unknown MarkupContent kind:', item.documentation.kind);
127126
}
128127
details += item.documentation.value;
129128
}
@@ -146,7 +145,9 @@ export function signatureToMarkdown(
146145
details = '<details>\n' + details + '\n</details>';
147146
}
148147
}
149-
markdown += details;
148+
markdown += '\n\n' + details;
149+
} else {
150+
markdown += '\n';
150151
}
151152
return markdown;
152153
}
@@ -181,7 +182,7 @@ export class SignatureCM extends CodeMirrorIntegration {
181182
// (allowing user to select/copy from signature)
182183
if (
183184
this.isSignatureShown() &&
184-
(event.target as Element).closest('.' + CLASS_NAME) === null
185+
(event.relatedTarget as Element).closest('.' + CLASS_NAME) === null
185186
) {
186187
this._hideTooltip();
187188
}
@@ -275,7 +276,7 @@ export class SignatureCM extends CodeMirrorIntegration {
275276
code.appendChild(element);
276277
}
277278
);
278-
return pre.outerHTML + '\n\n';
279+
return pre.outerHTML;
279280
}
280281

281282
/**

0 commit comments

Comments
 (0)