Skip to content

Commit

Permalink
feat(commands.extract): let user choose name
Browse files Browse the repository at this point in the history
  • Loading branch information
hiaux0 committed Dec 26, 2022
1 parent 5464ecc commit ecf01e8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 41 deletions.
12 changes: 3 additions & 9 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,14 @@ export async function activate(context: ExtensionContext) {
// vscode.window.showWarningMessage(message, 'Close')
// })

client.onRequest('get-component-name', () => {
getUserInputCommand(context);

var editor = window.activeTextEditor;
/* prettier-ignore */ console.log('>>>> _ >>>> ~ file: extension.ts ~ line 115 ~ editor?.selections', editor?.selections)

// const message = '[Aurelia] No tsconfig.json found. Please visit the [Usage section](https://github.com/aurelia/vscode-extension#1-usage) for more information.';
// window.showWarningMessage(message, 'Close')
client.onRequest('get-component-name', async () => {
const userInput = await getUserInputCommand(context);
return userInput;
});

client.onRequest('get-editer-selections', () => {
var editor = window.activeTextEditor;
const documentText = editor?.document.getText();
/* prettier-ignore */ console.log('>>>> _ >>>> ~ file: extension.ts ~ line 120 ~ documentText', documentText)
return {
documentText,
documentUri: editor?.document.uri.toString(),
Expand Down
37 changes: 10 additions & 27 deletions client/src/feature/userInput/userInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,14 @@ import { CREATE_COMPONEN_TEXT } from '../../shared/constants';
import { GetComponentState } from '../../shared/types/types';
import { multiStepInput } from './multiStepInput';

export function getUserInputCommand(context: ExtensionContext) {
// return commands.registerCommand('get-component-name', async () => {
const outsideState = {};
const options: {
[key: string]: (context: ExtensionContext) => Promise<void>;
} = {
[CREATE_COMPONEN_TEXT]: multiStepInput(
outsideState,
(state: GetComponentState) => {
/* prettier-ignore */ console.log('>>>> _ >>>> ~ file: userInput.ts ~ line 16 ~ state.name', state.name)
}
),
};
const quickPick = window.createQuickPick();
quickPick.items = Object.keys(options).map((label) => ({ label }));
quickPick.onDidChangeSelection((selection) => {
/* prettier-ignore */ console.log('>>>> _ >>>> ~ file: userInput.ts ~ line 16 ~ selection', selection)
if (selection[0]) {
options[selection[0].label](context).catch(console.error);
}
});
quickPick.onDidHide(() => {
/* prettier-ignore */ console.log('>>>> _ >>>> ~ file: userInput.ts ~ line 23 ~ outsideState', outsideState)
quickPick.dispose();
});
quickPick.show();
// });
export async function getUserInputCommand(context: ExtensionContext) {
const result = await window.showInputBox({
// value: 'abcdef',
// valueSelection: [2, 4],
placeHolder: 'Enter component name',
// validateInput: text => {
// return text === '123' ? 'Not 123!' : null;
// }
});
return result
}
13 changes: 8 additions & 5 deletions server/src/feature/commands/extractComponent/extractComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import {
GetEditorSelectionResponse,
UserSuppliedTemplatesFunctions,
} from '../../../common/types/types';
import { AureliaProjects, IAureliaProject } from '../../../core/AureliaProjects';
import {
AureliaProjects,
IAureliaProject,
} from '../../../core/AureliaProjects';
import {
AllDocumentsInjection,
ConnectionInjection,
Expand All @@ -24,6 +27,7 @@ import { AureliaUtils } from '../../../common/AureliaUtils';
import { IAureliaClassMember } from '../../../aot/aotTypes';

const workspaceUpdates = new WorkspaceUpdates();
const getComponentNameRequest = new RequestType('get-component-name');

export class ExtractComponent {
constructor(
Expand All @@ -34,8 +38,7 @@ export class ExtractComponent {
) {}

async initExtractComponent() {
// const componentName = await getComponentName(connection);
const componentName = 'hello-world';
const componentName = await this.getComponentName();
/* prettier-ignore */ console.log('>>>> _ >>>> ~ file: extractComponent.ts ~ line 7 ~ componentName', componentName)

// 2. Get Selection
Expand Down Expand Up @@ -198,8 +201,8 @@ export class ExtractComponent {
}

private async getComponentName() {
const req = new RequestType('get-component-name');
this.connection.sendRequest(req);
const result = await this.connection.sendRequest(getComponentNameRequest);
return result as string;
}

private extractSelectedTexts(
Expand Down

0 comments on commit ecf01e8

Please sign in to comment.