优化提示判断;过滤`.*`开头的文件;

master
yutent 2022-02-22 18:31:12 +08:00
parent fda19e7353
commit d3c043a218
3 changed files with 45 additions and 6 deletions

View File

@ -1,5 +1,9 @@
# 更新日志(Changed Logs)
### v1.1.0
- 优化提示判断, 当前输入需要在被引号包含中
- 过滤`.*`开头的文件
### v1.0.1
- 修复对json文件的支持

View File

@ -36,7 +36,7 @@ function isfile(path) {
function ls(dir) {
try {
var list = fs.readdirSync(dir)
return list.map(it => resolve(dir, it))
return list.filter(it => !it.startsWith('.')).map(it => resolve(dir, it))
} catch (err) {
return []
}
@ -45,7 +45,18 @@ function ls(dir) {
function getPrefixTxt(line, idx) {
var txt = line.slice(0, idx)
var n = txt.lastIndexOf('"') > -1 ? txt.lastIndexOf('"') : txt.lastIndexOf("'")
return txt.slice(n + 1)
var r
txt = txt.slice(n + 1)
if (txt) {
// 判断匹配前缀是否被包含在引号中
r = new RegExp(`(['"])${txt}\\1`)
if (r.test(line)) {
return txt
}
}
return ''
}
function item(text, type, p) {
@ -65,10 +76,33 @@ class AutoPath {
var inputTxt = doc.lineAt(pos).text // 获取光标所在的整行代码
var list = []
var currDirFixed = ''
var inputTxtTrim = inputTxt.trim()
// console.log('原始inputTxt >>>> ', inputTxt)
/**
* 过滤掉 以下几种情况
* @1 在注释后面的
* @2 当前光标在行末的
* @3 匹配前缀在行首的
*/
if (
inputTxtTrim.startsWith('// ') ||
inputTxtTrim.startsWith('/* ') ||
inputTxtTrim.startsWith('# ') ||
inputTxtTrim.startsWith('./') ||
inputTxtTrim.startsWith('../') ||
inputTxtTrim.startsWith('/') ||
inputTxtTrim.length === pos.character
) {
return
}
inputTxt = getPrefixTxt(inputTxt, pos.character)
currDirFixed = join(currDir, inputTxt)
// console.log('修正后的inputTxt: ', inputTxt)
if (!inputTxt) {
return
}
@ -111,9 +145,10 @@ class AutoPath {
return item(k, t, pos)
})
list.unshift(item('', FILE, pos))
return Promise.resolve(list)
if (list.length) {
list.unshift(item('', FILE, pos))
return Promise.resolve(list)
}
}
}

View File

@ -2,7 +2,7 @@
"name": "auto-path",
"displayName": "auto-path",
"description": "🔥 自动提示文件路径, 方便引入项目为的文件",
"version": "1.0.2",
"version": "1.1.0",
"publisher": "yutent",
"author": "Yutent [@yutent]",
"icon": "logo.png",