forked from micro-editor/go-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
dart.lua
47 lines (37 loc) · 1007 Bytes
/
dart.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
VERSION = "2.0.2"
local micro = import("micro")
local config = import("micro/config")
local shell = import("micro/shell")
local buffer = import("micro/buffer")
-- outside init because we want these options to take effect before
-- buffers are initialized
config.RegisterCommonOption("dart", "format", true)
function init()
config.MakeCommand("dartfmt", dartfmt, config.NoComplete)
config.AddRuntimeFile("dart", config.RTHelp, "help/dart-plugin.md")
end
function onSave(bp)
if bp.Buf:FileType() == "dart" then
if bp.Buf.Settings["dart.format"] then
dartfmt(bp)
end
end
return true
end
function dartfmt(bp)
bp:Save()
local _, err = shell.RunCommand("dart format " .. bp.Buf.Path)
if err ~= nil then
micro.InfoBar():Error(err)
return
end
bp.Buf:ReOpen()
end
function renameStderr(err)
micro.Log(err)
micro.InfoBar():Message(err)
end
function renameExit(output, args)
local bp = args[1]
bp.Buf:ReOpen()
end