Start adding some basic pinning tests for jsdoc -> snippet
This commit is contained in:
parent
83d4bb6b53
commit
7b3c343688
6 changed files with 1642 additions and 21 deletions
14
.vscode/launch.json
vendored
14
.vscode/launch.json
vendored
|
@ -173,6 +173,20 @@
|
|||
"${workspaceFolder}/extensions/markdown-language-features/out/**/*.js"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "extensionHost",
|
||||
"request": "launch",
|
||||
"name": "TypeScript Extension Tests",
|
||||
"runtimeExecutable": "${execPath}",
|
||||
"args": [
|
||||
"${workspaceFolder}/extensions/typescript-language-features/test-fixtures",
|
||||
"--extensionDevelopmentPath=${workspaceFolder}/extensions/typescript-language-features",
|
||||
"--extensionTestsPath=${workspaceFolder}/extensions/typescript-language-features/out/test"
|
||||
],
|
||||
"outFiles": [
|
||||
"${workspaceFolder}/extensions/typescript-language-features/out/**/*.js"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
|
|
|
@ -22,7 +22,8 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "8.0.33",
|
||||
"@types/semver": "5.4.0"
|
||||
"@types/semver": "5.4.0",
|
||||
"vscode": "^1.1.10"
|
||||
},
|
||||
"scripts": {
|
||||
"vscode:prepublish": "node ../../node_modules/gulp/bin/gulp.js --gulpfile ../../build/gulpfile.extensions.js compile-extension:typescript ./tsconfig.json"
|
||||
|
|
|
@ -176,28 +176,10 @@ class TryCompleteJsDocCommand implements Command {
|
|||
if (res.body.newText === '/** */') {
|
||||
return undefined;
|
||||
}
|
||||
return TryCompleteJsDocCommand.templateToSnippet(res.body.newText);
|
||||
return templateToSnippet(res.body.newText);
|
||||
}, () => undefined);
|
||||
}
|
||||
|
||||
private static templateToSnippet(template: string): SnippetString {
|
||||
// TODO: use append placeholder
|
||||
let snippetIndex = 1;
|
||||
template = template.replace(/^\s*(?=(\/|[ ]\*))/gm, '');
|
||||
template = template.replace(/^(\/\*\*\s*\*[ ]*)$/m, (x) => x + `\$0`);
|
||||
template = template.replace(/\* @param([ ]\{\S+\})?\s+(\S+)\s*$/gm, (_param, type, post) => {
|
||||
let out = '* @param ';
|
||||
if (type === ' {any}' || type === ' {*}') {
|
||||
out += `{\$\{${snippetIndex++}:*\}} `;
|
||||
} else if (type) {
|
||||
out += type + ' ';
|
||||
}
|
||||
out += post + ` \${${snippetIndex++}}`;
|
||||
return out;
|
||||
});
|
||||
return new SnippetString(template);
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert the default JSDoc
|
||||
*/
|
||||
|
@ -206,3 +188,22 @@ class TryCompleteJsDocCommand implements Command {
|
|||
return editor.insertSnippet(snippet, position, { undoStopBefore: false, undoStopAfter: true });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export function templateToSnippet(template: string): SnippetString {
|
||||
// TODO: use append placeholder
|
||||
let snippetIndex = 1;
|
||||
template = template.replace(/^\s*(?=(\/|[ ]\*))/gm, '');
|
||||
template = template.replace(/^(\/\*\*\s*\*[ ]*)$/m, (x) => x + `\$0`);
|
||||
template = template.replace(/\* @param([ ]\{\S+\})?\s+(\S+)\s*$/gm, (_param, type, post) => {
|
||||
let out = '* @param ';
|
||||
if (type === ' {any}' || type === ' {*}') {
|
||||
out += `{\$\{${snippetIndex++}:*\}} `;
|
||||
} else if (type) {
|
||||
out += type + ' ';
|
||||
}
|
||||
out += post + ` \${${snippetIndex++}}`;
|
||||
return out;
|
||||
});
|
||||
return new SnippetString(template);
|
||||
}
|
28
extensions/typescript-language-features/src/test/index.ts
Normal file
28
extensions/typescript-language-features/src/test/index.ts
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
//
|
||||
// PLEASE DO NOT MODIFY / DELETE UNLESS YOU KNOW WHAT YOU ARE DOING
|
||||
//
|
||||
// This file is providing the test runner to use when running extension tests.
|
||||
// By default the test runner in use is Mocha based.
|
||||
//
|
||||
// You can provide your own test runner if you want to override it by exporting
|
||||
// a function run(testRoot: string, clb: (error:Error) => void) that the extension
|
||||
// host can call to run the tests. The test runner is expected to use console.log
|
||||
// to report the results back to the caller. When the tests are finished, return
|
||||
// a possible error to the callback or null if none.
|
||||
|
||||
const testRunner = require('vscode/lib/testrunner');
|
||||
|
||||
// You can directly control Mocha options by uncommenting the following lines
|
||||
// See https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically#set-options for more info
|
||||
testRunner.configure({
|
||||
ui: 'tdd', // the TDD UI is being used in extension.test.ts (suite, test, etc.)
|
||||
useColors: process.platform !== 'win32', // colored output from test results (only windows cannot handle)
|
||||
timeout: 60000
|
||||
});
|
||||
|
||||
export = testRunner;
|
|
@ -0,0 +1,31 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as assert from 'assert';
|
||||
import * as vscode from 'vscode';
|
||||
import 'mocha';
|
||||
import { templateToSnippet } from '../features/jsDocCompletionProvider';
|
||||
|
||||
suite('typescript.jsDocSnippet', () => {
|
||||
test('Should do nothing for single line input', async () => {
|
||||
const input = `/** */`;
|
||||
assert.strictEqual(templateToSnippet(input).value, input);
|
||||
});
|
||||
|
||||
test('Should put curosr inside multiline line input', async () => {
|
||||
assert.strictEqual(
|
||||
templateToSnippet([
|
||||
'/**',
|
||||
' * ',
|
||||
' */'
|
||||
].join('\n')).value,
|
||||
[
|
||||
'/**',
|
||||
' * $0',
|
||||
' */'
|
||||
].join('\n'));
|
||||
});
|
||||
});
|
||||
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue