Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/support character completion #50

Merged
merged 2 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,14 @@ dist
# testing
/coverage

alova_tmp_*
alova_tmp_*

# test files
test/api-*/src/*
test/api-*/*openapi*.*
test/api-*/*swagger*.*
test/api-*/alova.config.*
!test/api-*/src/.gitkeep
!test/api-common/*openapi*.*
!test/api-common/*swagger*.*
!test/api-common/alova.config.*
2 changes: 1 addition & 1 deletion packages/vscode-extension/src/commands/autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default {
.map((line, idx) => `${idx > 0 ? preText : ''}${line}`)
.join('\n')
.trim();
const result = /(a->)(.*)/.exec(text);
const result = /(a-(>|》))(.*)/.exec(text);
editor.edit(editBuilder => {
editBuilder.replace(
new vscode.Range(new vscode.Position(position.line, result?.index ?? 0), position),
Expand Down
14 changes: 10 additions & 4 deletions packages/vscode-extension/src/components/autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@
import autocomplete from '@/functions/autocomplete';
import * as vscode from 'vscode';

const triggerCharacters: string[] = [' ', '.', '>', ':', '-'];
const triggerCharacters: string[] = [' ', '.', '>', '》', ':', '-'];
class AutoComplete extends vscode.CompletionItem {}
export default vscode.languages.registerCompletionItemProvider(
['javascript', 'typescript', 'vue', 'javascriptreact', 'typescriptreact', 'svelte'],
{
async provideCompletionItems(document: vscode.TextDocument, position: vscode.Position) {
async provideCompletionItems(
document: vscode.TextDocument,
position: vscode.Position,
_,
context: vscode.CompletionContext
) {
// Support newline code from starting position to input position
const text = document.lineAt(position).text.slice(0, position.character);
console.log('Trigger character:', context.triggerCharacter);

Check warning on line 18 in packages/vscode-extension/src/components/autocomplete.ts

View workflow job for this annotation

GitHub Actions / quality

Unexpected console statement
// const linePrefix = ;
if (/a->.*/.test(text)) {
const [, value] = /a->(.*)[\s.>:-]?/.exec(text) || [];
if (/a-(>|》).*/.test(text)) {
const [, , value] = /a-(>|》)(.*)[\s.>:-]?/.exec(text) || [];
return (await autocomplete(value.trim(), document.uri.fsPath)).map(item => {
const completionItem = new AutoComplete(item.path, vscode.CompletionItemKind.Function);
completionItem.detail = `[${item.method}] ${item.summary}`;
Expand Down
26 changes: 0 additions & 26 deletions test/api-common/src/api/apiDefinitions.js

This file was deleted.

103 changes: 0 additions & 103 deletions test/api-common/src/api/createApis.js

This file was deleted.

Loading
Loading