1
1
// The module 'vscode' contains the VS Code extensibility API
2
2
// Import the module and reference it with the alias vscode in your code below
3
3
import * as vscode from 'vscode' ;
4
- import * as path from 'path ' ;
4
+ import { generatePhpSkeleton } from './genetarePhpSkeletons ' ;
5
5
6
6
// This method is called when your extension is activated
7
7
// Your extension is activated the very first time the command is executed
8
8
export function activate ( context : vscode . ExtensionContext ) {
9
9
console . log ( 'Congratulations, your extension "php-class-generator" is now active!' ) ;
10
- context . subscriptions . push ( vscode . commands . registerCommand ( 'php-class-generator.generate-php-class' , generateFilePhpClass ) ) ;
10
+ context . subscriptions . push ( vscode . commands . registerCommand ( 'php-class-generator.generate-php-class' , generatePhpSkeleton ) ) ;
11
11
}
12
12
13
13
// This method is called when your extension is deactivated
14
- export function deactivate ( ) { }
15
-
16
-
17
- async function generateFilePhpClass ( ) {
18
-
19
- let className = await vscode . window . showInputBox ( {
20
- placeHolder : 'Name of class'
21
- } ) ;
22
-
23
- if ( ! className ) {
24
- vscode . window . showInformationMessage ( "It is required to provide a name for the class" ) ;
25
- return ;
26
- }
27
-
28
- className = capitalizeAndTrim ( className ) ;
29
- const classSkeleton = generateSkeleton ( className ) ;
30
-
31
- const pathFile = getPathFile ( className ) ;
32
- if ( ! pathFile ) {
33
- vscode . window . showInformationMessage ( "Working folder not found, open a folder an try again" ) ;
34
- return ;
35
- }
36
-
37
- // const rootPath = vscode.workspace.rootPath;
38
- // let pathFile = vscode.Uri.parse(`file:` + path.join(`${rootPath}`, `${className}.php`));
39
-
40
- await vscode . workspace . fs . writeFile ( pathFile , Buffer . from ( classSkeleton ) ) ;
41
- vscode . window . showTextDocument ( pathFile ) ;
42
- }
43
-
44
-
45
- function generateSkeleton ( className : string ) : string {
46
- return `<?php
47
-
48
- class ${ className }
49
- {
50
- public function __construct()
51
- {
52
- }
53
- }` ;
54
-
55
- }
56
-
57
- function getPathFile ( className : string ) : vscode . Uri | null {
58
-
59
- let fsPath = null ;
60
-
61
- // Create in current file directory
62
- if ( vscode . window . activeTextEditor ) {
63
- const currentlyOpenTabfileUri = vscode . window . activeTextEditor . document . uri ;
64
- const currentlyOpenTabfileName = path . basename ( currentlyOpenTabfileUri . toString ( ) ) ;
65
- fsPath = currentlyOpenTabfileUri . fsPath . replace ( currentlyOpenTabfileName , "" ) ;
66
- }
67
-
68
- // Create in root workspace
69
- if ( ! fsPath && vscode . workspace . workspaceFolders !== undefined ) {
70
- fsPath = vscode . workspace . workspaceFolders [ 0 ] . uri . fsPath ;
71
- }
72
-
73
- if ( fsPath ) {
74
- return vscode . Uri . parse ( `file:` + path . join ( `${ fsPath } ` , `${ className } .php` ) ) ;
75
- }
76
-
77
- return null ;
78
- }
79
-
80
- function capitalizeAndTrim ( str : string ) : string {
81
- const words = str . split ( ' ' ) ;
82
- let result = "" ;
83
- for ( let word of words ) {
84
- result += word . charAt ( 0 ) . toUpperCase ( ) + word . slice ( 1 ) ;
85
- }
86
- return result ;
87
- }
14
+ export function deactivate ( ) { }
0 commit comments