【问题标题】:Highlighting in custom SublimeLinter plugin在自定义 SublimeLinter 插件中突出显示
【发布时间】:2015-11-27 03:58:45
【问题描述】:

我开始为SublimeLinter 编写一个插件,到目前为止,linting 本身正在工作。但是,我还没有设法使突出显示工作。由于我的 linter(实际上是一个编译器)不输出列,如果失败的行被突出显示,我会很高兴。

linter.py 中的相关部分如下所示:

regex = (
  r'Error in script \".+?\" on line (?P<line>\d+) -- aborting creation process'
)
multiline = True
line_col_base = (1, 1)

来自 linter 可执行文件的示例错误如下所示:

Invalid command: Naem
Error in script "/Users/testuser/Desktop/lint-test.nsi" on line 5 -- aborting creation process

我不知道 SublimeLinter 是如何利用错误消息的,所以我很乐意现在得到 line 部分。

编辑:根据下面的评论,我尝试使用near,但由于文档稀缺且没有示例,我仍然没有找到解决方案。我更新的正则表达式模式:

regex = (
  r'Invalid command\: (?P<near>\w+)'
  r'Error in script \"(.+?)\" on line (?P<line>\d+) -- aborting creation process'
)

尽管这只会捕获拼写错误的命令,但答案可以让我更容易理解如何正确捕获输出。

【问题讨论】:

标签: python regex sublimetext sublimelinter


【解决方案1】:

这是我最终使用的:

syntax = 'nsis'
    regex = (
        r'(?P<message>[^\r?\n]+)\r?\n'
        r'(?P<error>Error) in script "[^"]+" on line (?P<line>\d+) -- aborting creation process'
    )
    multiline = True
    error_stream = util.STREAM_STDOUT
    line_col_base = (1, 1)

如果我没记错的话,是缺少换行符。

【讨论】:

    猜你喜欢
    • 2015-11-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-13
    • 1970-01-01
    • 2023-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多