Closed mgzenitech closed 5 months ago
Here's test that probably gives an idea on how to implement this:
it("will activate the Generate Docstring completion item after triple single quotes", async function () {
const settings = vsc.workspace.getConfiguration(settingsIdentifier);
await settings.update("quoteStyle", "'''", true);
await editor.edit((edit) => {
edit.insert(new vsc.Position(0, 0), "\n '''");
});
await vsc.commands.executeCommand("editor.action.triggerSuggest");
await delay(200);
await vsc.commands.executeCommand("acceptSelectedSuggestion");
await delay(600);
expect(document.getText()).to.contain("AI is creating summary for");
});
And here's probably actual code to attach the suggestions: https://github.com/graykode/ai-docstring/blob/ec5595dae9c8cebe31e8b30444abb0e8daf510c0/src/extension.ts#L27
['python', 'starlark'].map((language) => {
context.subscriptions.push(
vs.languages.registerCompletionItemProvider(
language,
{
provideCompletionItems: (document: vs.TextDocument, position: vs.Position, _: vs.CancellationToken) => {
if (validEnterActivation(document, position)) {
return [new AutoDocstringCompletionItem(document, position)];
}
},
},
"\"",
"'",
"#",
)
);
});
Maybe this can be implemented also in this extension?
Great suggestion. Will be done. Thank you!
There is this other extension (https://github.com/graykode/ai-docstring) that figured out a perfect way to trigger documentation generation more naturally than running commands.
Basically what happens, whenever someone wants to generate docs all you have to do is just go to function body and start typing """ and press enter.
Maybe this can be implemented also in this extension?