当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript TextEditor.getPath方法代码示例

本文整理汇总了TypeScript中atom.TextEditor.getPath方法的典型用法代码示例。如果您正苦于以下问题:TypeScript TextEditor.getPath方法的具体用法?TypeScript TextEditor.getPath怎么用?TypeScript TextEditor.getPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在atom.TextEditor的用法示例。


在下文中一共展示了TextEditor.getPath方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: async

  lint: async (textEditor: TextEditor): Promise<LintResult> => {
    const filePath = textEditor.getPath();

    if (!filePath) {
      // The current TextEditor has no path associated with it.
      return null;
    }

    const input = textEditor.getText();

    const command = atom.config.get("linter-swiftlint.swiftlintExecutablePath");
    if (!fs.existsSync(command)) {
      return null;
    }

    const parameters = ["lint", "--use-stdin"];
    let config = path.normalize(
      atom.config.get("linter-swiftlint.configurationPath")
    );

    if (filePath && !path.isAbsolute(config)) {
      config =
        atom.project
          .getDirectories()
          .filter(directory => directory.contains(filePath))
          .map(directory => directory.getFile(config).getPath())
          .find(() => true) || config; // take first item if exists
    }

    if (config && fs.existsSync(config)) {
      parameters.push("--config", config);
    }

    const additionalOptions = atom.config.get(
      "linter-swiftlint.additionalOptions"
    );
    if (additionalOptions) {
      parameters.push(additionalOptions);
    }

    const options = {
      ignoreExitCode: true,
      stdin: input,
      throwOnStderr: false
    };

    const output = await helpers.exec(command, parameters, options);

    const messages: Message[] = [];
    let match = regex.exec(output);
    while (match !== null) {
      const line = Math.max(Number.parseInt(match[1], 10) - 1, 0);
      const col = Math.max(Number.parseInt(match[2], 10) - 1, 0);
      let position: Range;
      try {
        position = helpers.generateRange(textEditor, line, col);
      } catch(e) {
        // If the position wasn't valid, just return the start of the file
        // NOTE: Ideally this would handle the error and give the user an easy
        // way to report it for eventual fixing.
        position = new Range([0, 0], [0, Number.POSITIVE_INFINITY]);
      }

      const type = match[3].toLowerCase();
      const severity =
        type === 'error' || type === 'warning' || type === 'info' ?
        type : 'error';

      messages.push({
        severity,
        excerpt: match[4],
        location: {
          file: filePath,
          position,
        }
      });

      // Pull in the next result (if any)
      match = regex.exec(output);
    }

    return messages;
  }
开发者ID:AtomLinter,项目名称:linter-swiftlint,代码行数:83,代码来源:linter-provider.ts


注:本文中的atom.TextEditor.getPath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。