Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wa-lang
wa
提交
a61c9d83
wa
项目概览
wa-lang
/
wa
10 个月 前同步成功
通知
68
Star
655
Fork
45
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
wa
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
a61c9d83
编写于
6月 27, 2023
作者:
chai2010
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修复并完善 fmt 命令
上级
db9d81ad
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
52 addition
and
11 deletion
+52
-11
api/api_test.go
api/api_test.go
+1
-1
internal/app/appfmt/appfmt.go
internal/app/appfmt/appfmt.go
+42
-6
internal/format/format.go
internal/format/format.go
+9
-4
未找到文件。
api/api_test.go
浏览文件 @
a61c9d83
...
...
@@ -8,7 +8,7 @@ import (
"wa-lang.org/wa/api"
)
func
_
ExampleFormatCode
()
{
func
ExampleFormatCode
()
{
s
,
err
:=
api
.
FormatCode
(
"hello.wa"
,
"func add(a:i32, b:i32)=>i32 {return a+b}"
)
if
err
!=
nil
{
panic
(
err
)
...
...
internal/app/appfmt/appfmt.go
浏览文件 @
a61c9d83
...
...
@@ -14,12 +14,25 @@ import (
func
Fmt
(
path
string
)
error
{
if
path
==
""
{
path
,
_
=
os
.
Getwd
()
path
=
"."
}
var
waFileList
[]
string
if
strings
.
HasSuffix
(
path
,
"..."
)
{
waFileList
=
getDirWaFileList
(
strings
.
TrimSuffix
(
path
,
"..."
))
switch
{
case
strings
.
HasSuffix
(
path
,
".wa"
)
:
waFileList
=
append
(
waFileList
,
path
)
case
strings
.
HasSuffix
(
path
,
".wz"
)
:
waFileList
=
append
(
waFileList
,
path
)
case
strings
.
HasSuffix
(
path
,
"..."
)
:
waFileList
=
getDirWaFileList
(
strings
.
TrimSuffix
(
path
,
"..."
),
true
,
".wa"
,
".wz"
,
// 包含子目录
)
default
:
// 不包含子目录
waFileList
=
getDirWaFileList
(
path
,
false
,
".wa"
,
".wz"
,
)
}
var
changedFileList
[]
string
...
...
@@ -51,8 +64,28 @@ func fmtFile(path string) (changed bool, err error) {
return
true
,
nil
}
func
getDirWaFileList
(
dir
string
)
[]
string
{
func
getDirWaFileList
(
dir
string
,
walkSubDir
bool
,
extList
...
string
)
[]
string
{
var
waFileList
[]
string
if
!
walkSubDir
{
files
,
err
:=
os
.
ReadDir
(
"."
)
if
err
!=
nil
{
return
nil
}
for
_
,
file
:=
range
files
{
if
file
.
IsDir
()
{
continue
}
for
_
,
ext
:=
range
extList
{
if
strings
.
HasSuffix
(
file
.
Name
(),
ext
)
{
waFileList
=
append
(
waFileList
,
filepath
.
Join
(
dir
,
file
.
Name
()))
}
}
}
sort
.
Strings
(
waFileList
)
return
waFileList
}
filepath
.
Walk
(
dir
,
func
(
path
string
,
info
os
.
FileInfo
,
err
error
)
error
{
if
err
!=
nil
{
return
err
...
...
@@ -60,8 +93,11 @@ func getDirWaFileList(dir string) []string {
if
info
.
IsDir
()
{
return
nil
}
if
strings
.
HasSuffix
(
path
,
".wa"
)
{
waFileList
=
append
(
waFileList
,
path
)
for
_
,
ext
:=
range
extList
{
if
strings
.
HasSuffix
(
path
,
ext
)
{
waFileList
=
append
(
waFileList
,
path
)
return
nil
}
}
return
nil
})
...
...
internal/format/format.go
浏览文件 @
a61c9d83
...
...
@@ -27,6 +27,7 @@ import (
"wa-lang.org/wa/internal/parser"
"wa-lang.org/wa/internal/printer"
"wa-lang.org/wa/internal/token"
"wa-lang.org/wa/internal/wamime"
)
var
config
=
printer
.
Config
{
Mode
:
printer
.
UseSpaces
|
printer
.
TabIndent
,
Tabwidth
:
8
}
...
...
@@ -65,11 +66,15 @@ func File(vfs fs.FS, filename string, src interface{}) (text []byte, changed boo
if
err
!=
nil
{
return
nil
,
false
,
err
}
golden
,
err
:=
SourceFile
(
text
)
if
!
bytes
.
Equal
(
text
,
golden
)
{
return
text
,
false
,
nil
// TODO: 支持中文格式化
if
wamime
.
GetCodeMime
(
filename
,
text
)
==
"wa"
{
golden
,
err
:=
SourceFile
(
text
)
if
bytes
.
Equal
(
text
,
golden
)
{
return
text
,
false
,
nil
}
return
golden
,
true
,
err
}
return
golden
,
tru
e
,
nil
return
text
,
fals
e
,
nil
}
// Node formats node in canonical gofmt style and writes the result to dst.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录