Skip to content

Commit e7a504c

Browse files
Yu ZhangDonJayamanne
authored andcommitted
📝 add comments for highlightCode method and fix unit tests (#1051)
* 📝 add comments for `highlightCode` method * 💚 fix unit tests * 💚 fix again
1 parent f9c7098 commit e7a504c

2 files changed

Lines changed: 20 additions & 11 deletions

File tree

src/client/providers/jediHelpers.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,16 @@ export function extractSignatureAndDocumentation(definition: proxy.IAutoComplete
4949
}
5050

5151
export function highlightCode(docstring: string): string {
52-
// Add blank line before and after docstring
52+
/**********
53+
*
54+
* Magic. Do not touch. [What is the best comment in source code](https://stackoverflow.com/a/185106)
55+
*
56+
* This method uses several regexs to 'translate' reStructruedText syntax (Python doc syntax) to Markdown syntax.
57+
*
58+
* Let's just keep it unchanged unless a better solution becomes possible.
59+
*
60+
**********/
61+
// Add 2 line break before and after docstring (used to match a blank line)
5362
docstring = EOL + EOL + docstring.trim() + EOL + EOL;
5463
// Section title -> heading level 2
5564
docstring = docstring.replace(/(.+\r?\n)[-=]+\r?\n/g, '## $1' + EOL);
@@ -93,5 +102,5 @@ export function highlightCode(docstring: string): string {
93102
// Grid Tables
94103
docstring = docstring.replace(/\r?\n[\+-]+\r?\n/g, EOL);
95104
docstring = docstring.replace(/\r?\n[\+=]+\r?\n/g, s => s.replace(/\+/g, '|').replace(/=/g, '-'));
96-
return docstring.trim() + EOL;
105+
return docstring.trim();
97106
}

src/test/extension.autocomplete.test.ts

Lines changed: 9 additions & 9 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 + 'This is method1' + EOL, 'function signature incorrect');
238+
assert.equal(def[0].contents[0], '```python' + EOL + 'def method1()' + EOL + '```' + EOL + 'This is method1', '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 + 'This is fun' + EOL, 'Invalid conents');
257+
assert.equal(def[0].contents[0], '```python' + EOL + 'def fun()' + EOL + '```' + EOL + 'This is fun', 'Invalid conents');
258258
}).then(done, done);
259259
});
260260

@@ -275,7 +275,7 @@ suite('Hover Definition', () => {
275275
assert.equal(`${def[0].range.end.line},${def[0].range.end.character}`, '25,7', 'End position is incorrect');
276276
assert.equal(def[0].contents[0], '```python' + EOL + 'def bar()' + EOL + '```' + EOL +
277277
'说明 - keep this line, it works' + EOL + 'delete following line, it works' +
278-
EOL + '如果存在需要等待审批或正在执行的任务,将不刷新页面' + EOL, 'Invalid conents');
278+
EOL + '如果存在需要等待审批或正在执行的任务,将不刷新页面', 'Invalid conents');
279279
}).then(done, done);
280280
});
281281

@@ -298,7 +298,7 @@ suite('Hover Definition', () => {
298298
'def showMessage()' + EOL +
299299
'```' + EOL +
300300
'Кюм ут жэмпэр пошжим льаборэж, коммюны янтэрэсщэт нам ед, декта игнота ныморэ жят эи. ' + EOL +
301-
'Шэа декам экшырки эи, эи зыд эррэм докэндё, векж факэтэ пэрчыквюэрёж ку.' + EOL, 'Invalid conents');
301+
'Шэа декам экшырки эи, эи зыд эррэм докэндё, векж факэтэ пэрчыквюэрёж ку.', 'Invalid conents');
302302
}).then(done, done);
303303
});
304304

@@ -363,7 +363,7 @@ suite('Hover Definition', () => {
363363
"`methods` random(), seed(), getstate(), and setstate()." + EOL +
364364
EOL +
365365
"Optionally, implement a getrandbits() method so that randrange()" + EOL +
366-
"can cover arbitrarily large ranges." + EOL;
366+
"can cover arbitrarily large ranges.";
367367

368368
assert.equal(def[0].contents[0], documentation, 'Invalid conents');
369369
}).then(done, done);
@@ -387,7 +387,7 @@ suite('Hover Definition', () => {
387387
assert.equal(def[0].contents[0], '```python' + EOL +
388388
'def randint(a, b)' + EOL +
389389
'```' + EOL +
390-
'Return random integer in range [a, b], including both end points.' + EOL,
390+
'Return random integer in range [a, b], including both end points.',
391391
'Invalid conents');
392392
}).then(done, done);
393393
});
@@ -410,7 +410,7 @@ suite('Hover Definition', () => {
410410
assert.equal(def[0].contents[0], '```python' + EOL +
411411
'def acos(x)' + EOL +
412412
'```' + EOL +
413-
'Return the arc cosine (measured in radians) of x.' + EOL,
413+
'Return the arc cosine (measured in radians) of x.',
414414
'Invalid conents');
415415
}).then(done, done);
416416
});
@@ -438,7 +438,7 @@ suite('Hover Definition', () => {
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.' + EOL,
441+
'This class can be safely subclassed in a limited fashion.',
442442
'Invalid content items');
443443
}).then(done, done);
444444
});
@@ -474,7 +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.` + EOL,
477+
can cover arbitrarily large ranges.`,
478478
'Invalid content items');
479479
}).then(done, done);
480480
});

0 commit comments

Comments
 (0)