Skip to content

Commit d65c9c3

Browse files
robodairDonJayamanne
authored andcommitted
Fix highlightCode docstring formatter + unit tests (#1048)
1 parent 590ecfc commit d65c9c3

2 files changed

Lines changed: 15 additions & 16 deletions

File tree

src/client/providers/jediHelpers.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export function extractSignatureAndDocumentation(definition: proxy.IAutoComplete
5050

5151
export function highlightCode(docstring: string): string {
5252
// Add blank line before and after docstring
53-
docstring = EOL + docstring.trim() + EOL;
53+
docstring = EOL + EOL + docstring.trim() + EOL + EOL;
5454
// Section title -> heading level 2
5555
docstring = docstring.replace(/(.+\r?\n)[-=]+\r?\n/g, '## $1' + EOL);
5656
// Directives: '.. directive::' -> '**directive**'
@@ -93,5 +93,5 @@ export function highlightCode(docstring: string): string {
9393
// Grid Tables
9494
docstring = docstring.replace(/\r?\n[\+-]+\r?\n/g, EOL);
9595
docstring = docstring.replace(/\r?\n[\+=]+\r?\n/g, s => s.replace(/\+/g, '|').replace(/=/g, '-'));
96-
return docstring;
97-
}
96+
return docstring.trim() + EOL;
97+
}

src/test/extension.autocomplete.test.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ suite('Hover Definition', () => {
235235
assert.equal(`${def[0].range.start.line},${def[0].range.start.character}`, '30,4', 'Start position is incorrect');
236236
assert.equal(`${def[0].range.end.line},${def[0].range.end.character}`, '30,11', 'End position is incorrect');
237237
assert.equal(def[0].contents.length, 1, 'Invalid content items');
238-
assert.equal(def[0].contents[0], '```python' + EOL + 'def method1()' + EOL + '```' + EOL + EOL + 'This is method1' + EOL, 'function signature incorrect');
238+
assert.equal(def[0].contents[0], '```python' + EOL + 'def method1()' + EOL + '```' + EOL + 'This is method1' + EOL, 'function signature incorrect');
239239
}).then(done, done);
240240
});
241241

@@ -254,7 +254,7 @@ suite('Hover Definition', () => {
254254
assert.equal(def.length, 1, 'Definition length is incorrect');
255255
assert.equal(`${def[0].range.start.line},${def[0].range.start.character}`, '1,9', 'Start position is incorrect');
256256
assert.equal(`${def[0].range.end.line},${def[0].range.end.character}`, '1,12', 'End position is incorrect');
257-
assert.equal(def[0].contents[0], '```python' + EOL + 'def fun()' + EOL + '```' + EOL + EOL + 'This is fun' + EOL, 'Invalid conents');
257+
assert.equal(def[0].contents[0], '```python' + EOL + 'def fun()' + EOL + '```' + EOL + 'This is fun' + EOL, 'Invalid conents');
258258
}).then(done, done);
259259
});
260260

@@ -273,7 +273,7 @@ suite('Hover Definition', () => {
273273
assert.equal(def.length, 1, 'Definition length is incorrect');
274274
assert.equal(`${def[0].range.start.line},${def[0].range.start.character}`, '25,4', 'Start position is incorrect');
275275
assert.equal(`${def[0].range.end.line},${def[0].range.end.character}`, '25,7', 'End position is incorrect');
276-
assert.equal(def[0].contents[0], '```python' + EOL + 'def bar()' + EOL + '```' + EOL + EOL +
276+
assert.equal(def[0].contents[0], '```python' + EOL + 'def bar()' + EOL + '```' + EOL +
277277
'说明 - keep this line, it works' + EOL + 'delete following line, it works' +
278278
EOL + '如果存在需要等待审批或正在执行的任务,将不刷新页面' + EOL, 'Invalid conents');
279279
}).then(done, done);
@@ -296,7 +296,7 @@ suite('Hover Definition', () => {
296296
assert.equal(`${def[0].range.end.line},${def[0].range.end.character}`, '1,16', 'End position is incorrect');
297297
assert.equal(def[0].contents[0], '```python' + EOL +
298298
'def showMessage()' + EOL +
299-
'```' + EOL + EOL +
299+
'```' + EOL +
300300
'Кюм ут жэмпэр пошжим льаборэж, коммюны янтэрэсщэт нам ед, декта игнота ныморэ жят эи. ' + EOL +
301301
'Шэа декам экшырки эи, эи зыд эррэм докэндё, векж факэтэ пэрчыквюэрёж ку.' + EOL, 'Invalid conents');
302302
}).then(done, done);
@@ -351,7 +351,7 @@ suite('Hover Definition', () => {
351351
assert.equal(`${def[0].range.end.line},${def[0].range.end.character}`, '11,18', 'End position is incorrect');
352352
let documentation = "```python" + EOL +
353353
"class Random(x=None)" + EOL +
354-
"```" + EOL + EOL +
354+
"```" + EOL +
355355
"Random number generator base class used by bound module functions." + EOL +
356356
"" + EOL +
357357
"Used to instantiate instances of Random to get generators that don't" + EOL +
@@ -386,7 +386,7 @@ suite('Hover Definition', () => {
386386
assert.equal(`${def[0].range.end.line},${def[0].range.end.character}`, '12,12', 'End position is incorrect');
387387
assert.equal(def[0].contents[0], '```python' + EOL +
388388
'def randint(a, b)' + EOL +
389-
'```' + EOL + EOL +
389+
'```' + EOL +
390390
'Return random integer in range [a, b], including both end points.' + EOL,
391391
'Invalid conents');
392392
}).then(done, done);
@@ -409,7 +409,7 @@ suite('Hover Definition', () => {
409409
assert.equal(`${def[0].range.end.line},${def[0].range.end.character}`, '8,15', 'End position is incorrect');
410410
assert.equal(def[0].contents[0], '```python' + EOL +
411411
'def acos(x)' + EOL +
412-
'```' + EOL + EOL +
412+
'```' + EOL +
413413
'Return the arc cosine (measured in radians) of x.' + EOL,
414414
'Invalid conents');
415415
}).then(done, done);
@@ -432,14 +432,14 @@ suite('Hover Definition', () => {
432432
assert.equal(`${def[0].range.end.line},${def[0].range.end.character}`, '14,15', 'End position is incorrect');
433433
assert.equal(def[0].contents[0], '```python' + EOL +
434434
'class Thread(group=None, target=None, name=None, args=(), kwargs=None, verbose=None)' + EOL +
435-
'```' + EOL + EOL +
435+
'```' + EOL +
436436
'Thread(self, group=None, target=None, name=None,' + EOL +
437437
'args=(), kwargs=None, verbose=None)' + EOL +
438438
'' + EOL +
439439
'A class that represents a thread of control.' + EOL +
440440
'' + EOL +
441-
'This class can be safely subclassed in a limited fashion.'
442-
+ EOL, 'Invalid content items');
441+
'This class can be safely subclassed in a limited fashion.' + EOL,
442+
'Invalid content items');
443443
}).then(done, done);
444444
});
445445

@@ -460,7 +460,7 @@ suite('Hover Definition', () => {
460460
assert.equal(def[0].contents[0],
461461
'```python' + EOL +
462462
'Random' + EOL +
463-
'```' + EOL + EOL +
463+
'```' + EOL +
464464
`Random(self, x=None)
465465
466466
Random number generator base class used by bound module functions.
@@ -474,8 +474,7 @@ generator of your own devising: in that case, override the following
474474
\`methods\` random(), seed(), getstate(), and setstate().
475475
476476
Optionally, implement a getrandbits() method so that randrange()
477-
can cover arbitrarily large ranges.
478-
`,
477+
can cover arbitrarily large ranges.` + EOL,
479478
'Invalid content items');
480479
}).then(done, done);
481480
});

0 commit comments

Comments
 (0)