當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。