-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support create component and improve jumpdef (#125)
* feat: support create component and improve jumpdef * chore: add eol
- Loading branch information
Showing
13 changed files
with
298 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
{ | ||
"name": "minapp-vscode", | ||
"displayName": "WXML - Language Service", | ||
"description": "微信小程序.wxml文件代码高亮,标签、属性的智能补全(同时支持原生小程序、mpvue 和 wepy 框架,并提供code snippets)", | ||
"version": "2.4.1", | ||
"description": "wechat miniprogram .wxml file syntax highlight,code autocomplete(support native miniprogram、mpvue and wepy framework,provide code snippets)", | ||
"version": "2.4.2", | ||
"publisher": "qiu8310", | ||
"extensionKind": [ | ||
"workspace" | ||
|
@@ -18,8 +18,9 @@ | |
"clear": "rm -rf ./dist" | ||
}, | ||
"keywords": [ | ||
"小程序", | ||
"微信", | ||
"小程序", | ||
"minapp", | ||
"wxml", | ||
"wxss", | ||
"wxs", | ||
|
@@ -28,7 +29,7 @@ | |
], | ||
"license": "MIT", | ||
"author": "Mora <[email protected]> (https://github.com/qiu8310)", | ||
"contributors": [ | ||
"maintainers": [ | ||
{ | ||
"name": "Lei Chen", | ||
"email": "[email protected]", | ||
|
@@ -50,6 +51,8 @@ | |
], | ||
"activationEvents": [ | ||
"workspaceContains:minapp.cjson", | ||
"workspaceContains:**/project.config.json", | ||
"workspaceContains:**/app.wxss", | ||
"onLanguage:wxml-pug", | ||
"onLanguage:wxml", | ||
"onLanguage:vue" | ||
|
@@ -184,6 +187,39 @@ | |
}, | ||
"description": "全局的样式文件,系统会自动从这些指定的文件中获取 className,用于模板中的 class 补全" | ||
}, | ||
"minapp-vscode.wxmlExtname": { | ||
"type": "string", | ||
"default": "wxml", | ||
"enum": [ | ||
"wxml", | ||
"vue", | ||
"wpy" | ||
], | ||
"description": "创建小程序组件时候wxml文件类型,默认为.wxml" | ||
}, | ||
"minapp-vscode.jsExtname": { | ||
"type": "string", | ||
"default": "js", | ||
"enum": [ | ||
"js", | ||
"ts", | ||
"coffee" | ||
], | ||
"description": "创建小程序组件时候js文件类型,默认为.js" | ||
}, | ||
"minapp-vscode.cssExtname": { | ||
"type": "string", | ||
"default": "wxss", | ||
"enum": [ | ||
"wxss", | ||
"css", | ||
"styl", | ||
"less", | ||
"sass", | ||
"scss" | ||
], | ||
"description": "创建小程序组件时候css样式文件类型,默认为.wxss" | ||
}, | ||
"minapp-vscode.styleExtensions": { | ||
"type": "array", | ||
"items": { | ||
|
@@ -193,7 +229,9 @@ | |
"wxss", | ||
"css", | ||
"less", | ||
"scss" | ||
"scss", | ||
"sass", | ||
"styl" | ||
], | ||
"description": "当前样式文件的后缀中,系统会自动查找和当前模板同名的样式文件,用于模板中的 class 补全" | ||
}, | ||
|
@@ -253,6 +291,22 @@ | |
} | ||
} | ||
}, | ||
"menus": { | ||
"explorer/context": [ | ||
{ | ||
"command": "minapp-vscode.createMiniprogramComponent", | ||
"group": "navigation@10", | ||
"when": "resourceExtname == '' && activeViewlet == 'workbench.view.explorer'" | ||
} | ||
] | ||
}, | ||
"commands": [ | ||
{ | ||
"command": "minapp-vscode.createMiniprogramComponent", | ||
"title": "New Miniprogram Component", | ||
"category": "minapp-vscode" | ||
} | ||
], | ||
"themes": [], | ||
"languages": [ | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const COMMANDS = { | ||
createComponent: 'minapp-vscode.createMiniprogramComponent' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Uri, window, workspace } from 'vscode'; | ||
import * as fs from 'fs/promises'; | ||
import * as path from 'path'; | ||
|
||
import { config } from '../plugin/lib/config'; | ||
|
||
const jsonTpl = | ||
`{ | ||
"component": true | ||
} | ||
`; | ||
|
||
/** | ||
* create a new miniprogram component | ||
* | ||
* my-component | ||
* |- my-component.json | ||
* |- my-component.wxml | ||
* |- my-component.js | ||
* |- my-component.wxss | ||
*/ | ||
export async function createMiniprogramComponent(folderPath: Uri): Promise<void> { | ||
const input = await window.showInputBox({ | ||
prompt: "Enter the component name", | ||
validateInput: (s: string): string | undefined => s && s.trim() ? undefined : "Component name must not be empty.", | ||
placeHolder: "Example: avatar (will create 4 files, default is avatar.wxss avatar.json avatar.js avatar.wxml)", | ||
ignoreFocusOut: true, | ||
}) | ||
const componentName = input?.trim(); | ||
if (componentName) { | ||
fs.mkdir(path.join(folderPath.fsPath, componentName)).then(() => { | ||
Promise.all([ | ||
fs.writeFile(path.join(folderPath.fsPath, componentName, componentName + '.' + config.jsExtname), ""), | ||
fs.writeFile(path.join(folderPath.fsPath, componentName, componentName + '.' + config.cssExtname), ""), | ||
fs.writeFile(path.join(folderPath.fsPath, componentName, componentName + '.' + config.wxmlExtname), ""), | ||
fs.writeFile(path.join(folderPath.fsPath, componentName, componentName + '.json'), jsonTpl) | ||
]).then(() => { | ||
const openJsPath = Uri.file(path.join(folderPath.fsPath, componentName, componentName + '.' + config.jsExtname)); | ||
workspace.openTextDocument(openJsPath).then(doc => { | ||
if (doc) { | ||
window.showTextDocument(doc); | ||
} | ||
}); | ||
}).catch(err => { | ||
window.showErrorMessage(`create file error: ${err}`) | ||
}) | ||
}).catch(err => { | ||
window.showErrorMessage(`create folder error: ${err}`) | ||
}) | ||
} | ||
} |
Oops, something went wrong.