mirror of
https://github.com/Microsoft/vscode
synced 2024-09-13 21:55:38 +00:00
Add setting to enable/disable returns generation in jsdoc
Fixes #116282
This commit is contained in:
parent
a025039b4e
commit
3dc8cb1afc
|
@ -602,6 +602,18 @@
|
||||||
"description": "%configuration.suggest.completeJSDocs%",
|
"description": "%configuration.suggest.completeJSDocs%",
|
||||||
"scope": "resource"
|
"scope": "resource"
|
||||||
},
|
},
|
||||||
|
"javascript.suggest.jsdoc.generateReturns": {
|
||||||
|
"type": "boolean",
|
||||||
|
"default": true,
|
||||||
|
"markdownDescription": "%configuration.suggest.jsdoc.generateReturns%",
|
||||||
|
"scope": "resource"
|
||||||
|
},
|
||||||
|
"typescript.suggest.jsdoc.generateReturns": {
|
||||||
|
"type": "boolean",
|
||||||
|
"default": true,
|
||||||
|
"markdownDescription": "%configuration.suggest.jsdoc.generateReturns%",
|
||||||
|
"scope": "resource"
|
||||||
|
},
|
||||||
"typescript.locale": {
|
"typescript.locale": {
|
||||||
"type": [
|
"type": [
|
||||||
"string",
|
"string",
|
||||||
|
|
|
@ -68,6 +68,7 @@
|
||||||
"configuration.javascript.checkJs.experimentalDecorators.deprecation": "This setting has been deprecated in favor of `js/ts.implicitProjectConfig.experimentalDecorators`.",
|
"configuration.javascript.checkJs.experimentalDecorators.deprecation": "This setting has been deprecated in favor of `js/ts.implicitProjectConfig.experimentalDecorators`.",
|
||||||
"configuration.implicitProjectConfig.strictNullChecks": "Enable/disable [strict null checks](https://www.typescriptlang.org/tsconfig#strictNullChecks) in JavaScript and TypeScript files that are not part of a project. Existing `jsconfig.json` or `tsconfig.json` files override this setting.",
|
"configuration.implicitProjectConfig.strictNullChecks": "Enable/disable [strict null checks](https://www.typescriptlang.org/tsconfig#strictNullChecks) in JavaScript and TypeScript files that are not part of a project. Existing `jsconfig.json` or `tsconfig.json` files override this setting.",
|
||||||
"configuration.implicitProjectConfig.strictFunctionTypes": "Enable/disable [strict function types](https://www.typescriptlang.org/tsconfig#strictFunctionTypes) in JavaScript and TypeScript files that are not part of a project. Existing `jsconfig.json` or `tsconfig.json` files override this setting.",
|
"configuration.implicitProjectConfig.strictFunctionTypes": "Enable/disable [strict function types](https://www.typescriptlang.org/tsconfig#strictFunctionTypes) in JavaScript and TypeScript files that are not part of a project. Existing `jsconfig.json` or `tsconfig.json` files override this setting.",
|
||||||
|
"configuration.suggest.jsdoc.generateReturns": "Enable/disable generating `@return` annotations for JSDoc templates. Requires using TypeScript 4.2+ in the workspace.",
|
||||||
"configuration.suggest.autoImports": "Enable/disable auto import suggestions.",
|
"configuration.suggest.autoImports": "Enable/disable auto import suggestions.",
|
||||||
"taskDefinition.tsconfig.description": "The tsconfig file that defines the TS build.",
|
"taskDefinition.tsconfig.description": "The tsconfig file that defines the TS build.",
|
||||||
"javascript.suggestionActions.enabled": "Enable/disable suggestion diagnostics for JavaScript files in the editor.",
|
"javascript.suggestionActions.enabled": "Enable/disable suggestion diagnostics for JavaScript files in the editor.",
|
||||||
|
|
|
@ -182,6 +182,7 @@ export default class FileConfigurationManager extends Disposable {
|
||||||
allowRenameOfImportPath: true,
|
allowRenameOfImportPath: true,
|
||||||
includeAutomaticOptionalChainCompletions: config.get<boolean>('suggest.includeAutomaticOptionalChainCompletions', true),
|
includeAutomaticOptionalChainCompletions: config.get<boolean>('suggest.includeAutomaticOptionalChainCompletions', true),
|
||||||
provideRefactorNotApplicableReason: true,
|
provideRefactorNotApplicableReason: true,
|
||||||
|
generateReturnInDocTemplate: config.get<boolean>('suggest.jsdoc.generateReturns', true),
|
||||||
};
|
};
|
||||||
|
|
||||||
return preferences;
|
return preferences;
|
||||||
|
|
|
@ -9,6 +9,7 @@ import { ITypeScriptServiceClient } from '../typescriptService';
|
||||||
import { conditionalRegistration, requireConfiguration } from '../utils/dependentRegistration';
|
import { conditionalRegistration, requireConfiguration } from '../utils/dependentRegistration';
|
||||||
import { DocumentSelector } from '../utils/documentSelector';
|
import { DocumentSelector } from '../utils/documentSelector';
|
||||||
import * as typeConverters from '../utils/typeConverters';
|
import * as typeConverters from '../utils/typeConverters';
|
||||||
|
import FileConfigurationManager from './fileConfigurationManager';
|
||||||
|
|
||||||
|
|
||||||
const localize = nls.loadMessageBundle();
|
const localize = nls.loadMessageBundle();
|
||||||
|
@ -37,6 +38,7 @@ class JsDocCompletionProvider implements vscode.CompletionItemProvider {
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly client: ITypeScriptServiceClient,
|
private readonly client: ITypeScriptServiceClient,
|
||||||
|
private readonly fileConfigurationManager: FileConfigurationManager,
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
public async provideCompletionItems(
|
public async provideCompletionItems(
|
||||||
|
@ -53,8 +55,12 @@ class JsDocCompletionProvider implements vscode.CompletionItemProvider {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const response = await this.client.interruptGetErr(async () => {
|
||||||
|
await this.fileConfigurationManager.ensureConfigurationForDocument(document, token);
|
||||||
|
|
||||||
const args = typeConverters.Position.toFileLocationRequestArgs(file, position);
|
const args = typeConverters.Position.toFileLocationRequestArgs(file, position);
|
||||||
const response = await this.client.execute('docCommentTemplate', args, token);
|
return this.client.execute('docCommentTemplate', args, token);
|
||||||
|
});
|
||||||
if (response.type !== 'response' || !response.body) {
|
if (response.type !== 'response' || !response.body) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
@ -107,6 +113,9 @@ export function templateToSnippet(template: string): vscode.SnippetString {
|
||||||
out += post + ` \${${snippetIndex++}}`;
|
out += post + ` \${${snippetIndex++}}`;
|
||||||
return out;
|
return out;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
template = template.replace(/\* @returns[ \t]*$/gm, `* @returns \${${snippetIndex++}}`);
|
||||||
|
|
||||||
return new vscode.SnippetString(template);
|
return new vscode.SnippetString(template);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,12 +123,14 @@ export function register(
|
||||||
selector: DocumentSelector,
|
selector: DocumentSelector,
|
||||||
modeId: string,
|
modeId: string,
|
||||||
client: ITypeScriptServiceClient,
|
client: ITypeScriptServiceClient,
|
||||||
|
fileConfigurationManager: FileConfigurationManager,
|
||||||
|
|
||||||
): vscode.Disposable {
|
): vscode.Disposable {
|
||||||
return conditionalRegistration([
|
return conditionalRegistration([
|
||||||
requireConfiguration(modeId, 'suggest.completeJSDocs')
|
requireConfiguration(modeId, 'suggest.completeJSDocs')
|
||||||
], () => {
|
], () => {
|
||||||
return vscode.languages.registerCompletionItemProvider(selector.syntax,
|
return vscode.languages.registerCompletionItemProvider(selector.syntax,
|
||||||
new JsDocCompletionProvider(client),
|
new JsDocCompletionProvider(client, fileConfigurationManager),
|
||||||
'*');
|
'*');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,7 @@ export default class LanguageProvider extends Disposable {
|
||||||
import('./languageFeatures/formatting').then(provider => this._register(provider.register(selector, this.description.id, this.client, this.fileConfigurationManager))),
|
import('./languageFeatures/formatting').then(provider => this._register(provider.register(selector, this.description.id, this.client, this.fileConfigurationManager))),
|
||||||
import('./languageFeatures/hover').then(provider => this._register(provider.register(selector, this.client))),
|
import('./languageFeatures/hover').then(provider => this._register(provider.register(selector, this.client))),
|
||||||
import('./languageFeatures/implementations').then(provider => this._register(provider.register(selector, this.client))),
|
import('./languageFeatures/implementations').then(provider => this._register(provider.register(selector, this.client))),
|
||||||
import('./languageFeatures/jsDocCompletions').then(provider => this._register(provider.register(selector, this.description.id, this.client))),
|
import('./languageFeatures/jsDocCompletions').then(provider => this._register(provider.register(selector, this.description.id, this.client, this.fileConfigurationManager))),
|
||||||
import('./languageFeatures/organizeImports').then(provider => this._register(provider.register(selector, this.client, this.commandManager, this.fileConfigurationManager, this.telemetryReporter))),
|
import('./languageFeatures/organizeImports').then(provider => this._register(provider.register(selector, this.client, this.commandManager, this.fileConfigurationManager, this.telemetryReporter))),
|
||||||
import('./languageFeatures/quickFix').then(provider => this._register(provider.register(selector, this.client, this.fileConfigurationManager, this.commandManager, this.client.diagnosticsManager, this.telemetryReporter))),
|
import('./languageFeatures/quickFix').then(provider => this._register(provider.register(selector, this.client, this.fileConfigurationManager, this.commandManager, this.client.diagnosticsManager, this.telemetryReporter))),
|
||||||
import('./languageFeatures/refactor').then(provider => this._register(provider.register(selector, this.client, this.fileConfigurationManager, this.commandManager, this.telemetryReporter))),
|
import('./languageFeatures/refactor').then(provider => this._register(provider.register(selector, this.client, this.fileConfigurationManager, this.commandManager, this.telemetryReporter))),
|
||||||
|
|
Loading…
Reference in a new issue