• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript vscode-emmet-helper.doComplete函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中vscode-emmet-helper.doComplete函数的典型用法代码示例。如果您正苦于以下问题:TypeScript doComplete函数的具体用法?TypeScript doComplete怎么用?TypeScript doComplete使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: getStyleMode

function getStyleMode(
  languageId: string,
  languageService: LanguageService,
  documentRegions: LanguageModelCache<PaperclipDocumentRegions>
): LanguageMode {
  const embeddedDocuments = getLanguageModelCache(10, 60, document =>
    documentRegions.get(document).getEmbeddedDocument(languageId)
  );
  const stylesheets = getLanguageModelCache(10, 60, document => languageService.parseStylesheet(document));
  let config: any = {};

  return {
    getId() {
      return languageId;
    },
    configure(c) {
      languageService.configure(c && c.css);
      config = c;
    },
    async doValidation(document) {
      const embedded = embeddedDocuments.get(document);
      return await languageService.doValidation(embedded, stylesheets.get(embedded));
    },
    doComplete(document, position) {
      const embedded = embeddedDocuments.get(document);
      const emmetCompletions: CompletionList = emmet.doComplete(document, position, languageId, {
        useNewEmmet: true,
        showExpandedAbbreviation: true,
        showAbbreviationSuggestions: true,
        syntaxProfiles: {},
        variables: {}
      });
      const emmetItems = _.map(emmetCompletions.items, i => {
        return {
          ...i,
          sortText: Priority.Emmet + i.label
        };
      });
      const lsCompletions = languageService.doComplete(embedded, position, stylesheets.get(embedded));
      const lsItems = lsCompletions ? _.map(lsCompletions.items, i => {
        return {
          ...i,
          sortText: Priority.Platform + i.label
        };
      }) : [];
      return {
        isIncomplete: true,
        items: _.concat(emmetItems, lsItems)
      };
    },
    doHover(document, position) {
      const embedded = embeddedDocuments.get(document);
      return languageService.doHover(embedded, position, stylesheets.get(embedded)) || NULL_HOVER;
    },
    findDocumentHighlight(document, position) {
      const embedded = embeddedDocuments.get(document);
      return languageService.findDocumentHighlights(embedded, position, stylesheets.get(embedded));
    },
    findDocumentSymbols(document) {
      const embedded = embeddedDocuments.get(document);
      return languageService.findDocumentSymbols(embedded, stylesheets.get(embedded));
    },
    findDefinition(document, position) {
      const embedded = embeddedDocuments.get(document);
      return languageService.findDefinition(embedded, position, stylesheets.get(embedded));
    },
    findReferences(document, position) {
      const embedded = embeddedDocuments.get(document);
      return languageService.findReferences(embedded, position, stylesheets.get(embedded));
    },
    findDocumentColors(document) {
      const embedded = embeddedDocuments.get(document);
      return languageService.findDocumentColors(embedded, stylesheets.get(embedded));
    },
    getColorPresentations(document, color, range) {
      const embedded = embeddedDocuments.get(document);
      return languageService.getColorPresentations(embedded, stylesheets.get(embedded), color, range);
    },
    format(document, currRange, formattingOptions) {
      if (config.tandem.paperclip.format.defaultFormatter[languageId] === 'none') {
        return [];
      }

      const { value, range } = getValueAndRange(document, currRange);
      const needIndent = config.tandem.paperclip.format.styleInitialIndent;
      const parserMap: { [k: string]: ParserOption } = {
        css: 'css'
      };
      return prettierify(
        value,
        getFileFsPath(document.uri),
        range,
        needIndent,
        formattingOptions,
        config.prettier,
        parserMap[languageId]
      );
    },
    onDocumentRemoved(document) {
      embeddedDocuments.onDocumentRemoved(document);
//.........这里部分代码省略.........
开发者ID:cryptobuks,项目名称:tandem,代码行数:101,代码来源:index.ts


示例2: getStyleMode

function getStyleMode(
  languageId: string,
  languageService: LanguageService,
  documentRegions: LanguageModelCache<VueDocumentRegions>
): LanguageMode {
  const embeddedDocuments = getLanguageModelCache(10, 60, document =>
    documentRegions.get(document).getEmbeddedDocument(languageId)
  );
  const stylesheets = getLanguageModelCache(10, 60, document => languageService.parseStylesheet(document));
  let config: any = {};

  return {
    getId() {
      return languageId;
    },
    configure(c) {
      languageService.configure(c && c.css);
      config = c;
    },
    doValidation(document) {
      if (languageId === 'postcss') {
        return [];
      } else {
        const embedded = embeddedDocuments.get(document);
        return languageService.doValidation(embedded, stylesheets.get(embedded));
      }
    },
    doComplete(document, position) {
      const embedded = embeddedDocuments.get(document);
      const emmetSyntax = languageId === 'postcss' ? 'css' : languageId;
      const lsCompletions = languageService.doComplete(embedded, position, stylesheets.get(embedded));
      const lsItems = lsCompletions ? _.map(lsCompletions.items, i => {
        return {
          ...i,
          sortText: Priority.Platform + i.label
        };
      }) : [];

      const emmetCompletions = emmet.doComplete(document, position, emmetSyntax, config.emmet);
      if (!emmetCompletions) {
        return { isIncomplete: false, items: lsItems };
      } else {
        const emmetItems = _.map(emmetCompletions.items, i => {
          return {
            ...i,
            sortText: Priority.Emmet + i.label
          };
        });
        return {
          isIncomplete: emmetCompletions.isIncomplete,
          items: _.concat(emmetItems, lsItems)
        };
      }
    },
    doHover(document, position) {
      const embedded = embeddedDocuments.get(document);
      return languageService.doHover(embedded, position, stylesheets.get(embedded)) || NULL_HOVER;
    },
    findDocumentHighlight(document, position) {
      const embedded = embeddedDocuments.get(document);
      return languageService.findDocumentHighlights(embedded, position, stylesheets.get(embedded));
    },
    findDocumentSymbols(document) {
      const embedded = embeddedDocuments.get(document);
      return languageService.findDocumentSymbols(embedded, stylesheets.get(embedded));
    },
    findDefinition(document, position) {
      const embedded = embeddedDocuments.get(document);
      return languageService.findDefinition(embedded, position, stylesheets.get(embedded));
    },
    findReferences(document, position) {
      const embedded = embeddedDocuments.get(document);
      return languageService.findReferences(embedded, position, stylesheets.get(embedded));
    },
    findDocumentColors(document) {
      const embedded = embeddedDocuments.get(document);
      return languageService.findDocumentColors(embedded, stylesheets.get(embedded));
    },
    getColorPresentations(document, color, range) {
      const embedded = embeddedDocuments.get(document);
      return languageService.getColorPresentations(embedded, stylesheets.get(embedded), color, range);
    },
    format(document, currRange, formattingOptions) {
      if (config.vetur.format.defaultFormatter[languageId] === 'none') {
        return [];
      }

      const { value, range } = getValueAndRange(document, currRange);
      const needIndent = config.vetur.format.styleInitialIndent;
      const parserMap: { [k: string]: ParserOption } = {
        css: 'css',
        postcss: 'css',
        scss: 'scss',
        less: 'less'
      };
      return prettierify(
        value,
        getFileFsPath(document.uri),
        range,
        needIndent,
//.........这里部分代码省略.........
开发者ID:tiravata,项目名称:vetur,代码行数:101,代码来源:index.ts


示例3: doComplete

export function doComplete(
  document: TextDocument,
  position: Position,
  htmlDocument: HTMLDocument,
  tagProviders: IHTMLTagProvider[],
  emmetConfig: emmet.EmmetConfiguration
): CompletionList {
  const result: CompletionList = {
    isIncomplete: false,
    items: []
  };

  const offset = document.offsetAt(position);
  const node = htmlDocument.findNodeBefore(offset);
  if (!node || node.isInterpolation) {
    return result;
  }
  const text = document.getText();
  const scanner = createScanner(text, node.start);
  let currentTag: string;
  let currentAttributeName: string;

  function getReplaceRange(replaceStart: number, replaceEnd: number = offset): Range {
    if (replaceStart > offset) {
      replaceStart = offset;
    }
    return { start: document.positionAt(replaceStart), end: document.positionAt(replaceEnd) };
  }

  function collectOpenTagSuggestions(afterOpenBracket: number, tagNameEnd?: number): CompletionList {
    const range = getReplaceRange(afterOpenBracket, tagNameEnd);
    tagProviders.forEach(provider => {
      const priority = provider.priority;
      provider.collectTags((tag, label) => {
        result.items.push({
          label: tag,
          kind: CompletionItemKind.Property,
          documentation: label,
          textEdit: TextEdit.replace(range, tag),
          sortText: priority + tag,
          insertTextFormat: InsertTextFormat.PlainText
        });
      });
    });
    return result;
  }

  function getLineIndent(offset: number) {
    let start = offset;
    while (start > 0) {
      const ch = text.charAt(start - 1);
      if ('\n\r'.indexOf(ch) >= 0) {
        return text.substring(start, offset);
      }
      if (!isWhiteSpace(ch)) {
        return null;
      }
      start--;
    }
    return text.substring(0, offset);
  }

  function collectCloseTagSuggestions(
    afterOpenBracket: number,
    matchingOnly: boolean,
    tagNameEnd: number = offset
  ): CompletionList {
    const range = getReplaceRange(afterOpenBracket, tagNameEnd);
    const closeTag = isFollowedBy(text, tagNameEnd, ScannerState.WithinEndTag, TokenType.EndTagClose) ? '' : '>';
    let curr = node;
    while (curr) {
      const tag = curr.tag;
      if (tag && (!curr.closed || curr.endTagStart && (curr.endTagStart > offset))) {
        const item: CompletionItem = {
          label: '/' + tag,
          kind: CompletionItemKind.Property,
          filterText: '/' + tag + closeTag,
          textEdit: TextEdit.replace(range, '/' + tag + closeTag),
          insertTextFormat: InsertTextFormat.PlainText
        };
        const startIndent = getLineIndent(curr.start);
        const endIndent = getLineIndent(afterOpenBracket - 1);
        if (startIndent !== null && endIndent !== null && startIndent !== endIndent) {
          const insertText = startIndent + '</' + tag + closeTag;
          (item.textEdit = TextEdit.replace(getReplaceRange(afterOpenBracket - 1 - endIndent.length), insertText)),
            (item.filterText = endIndent + '</' + tag + closeTag);
        }
        result.items.push(item);
        return result;
      }
      curr = curr.parent;
    }
    if (matchingOnly) {
      return result;
    }

    tagProviders.forEach(provider => {
      provider.collectTags((tag, label) => {
        result.items.push({
          label: '/' + tag,
//.........这里部分代码省略.........
开发者ID:tiravata,项目名称:vetur,代码行数:101,代码来源:htmlCompletion.ts


示例4: getStylusMode

export function getStylusMode(documentRegions: LanguageModelCache<VueDocumentRegions>): LanguageMode {
  const embeddedDocuments = getLanguageModelCache(10, 60, document =>
    documentRegions.get(document).getEmbeddedDocument('stylus')
  );
  let baseIndentShifted = false;
  let config: any = {};
  return {
    getId: () => 'stylus',
    configure(c) {
      baseIndentShifted = _.get(c, 'vetur.format.styleInitialIndent', false);
      config = c;
    },
    onDocumentRemoved() {},
    dispose() {},
    doComplete(document, position) {
      const embedded = embeddedDocuments.get(document);

      const lsCompletions = provideCompletionItems(embedded, position);
      const lsItems = _.map(lsCompletions.items, i => {
        return {
          ...i,
          sortText: Priority.Platform + i.label
        };
      });

      const emmetCompletions: CompletionList = emmet.doComplete(document, position, 'stylus', config.emmet);
      if (!emmetCompletions) {
        return { isIncomplete: false, items: lsItems };
      } else {
        const emmetItems = _.map(emmetCompletions.items, i => {
          return {
            ...i,
            sortText: Priority.Emmet + i.label
          };
        });
        return {
          isIncomplete: emmetCompletions.isIncomplete,
          items: _.concat(emmetItems, lsItems)
        };
      }
    },
    findDocumentSymbols(document) {
      const embedded = embeddedDocuments.get(document);
      return provideDocumentSymbols(embedded);
    },
    doHover(document, position) {
      const embedded = embeddedDocuments.get(document);
      return stylusHover(embedded, position);
    },
    format(document, range, formatParams) {
      if (config.vetur.format.defaultFormatter.stylus === 'none') {
        return [];
      }

      const embedded = embeddedDocuments.get(document);
      const inputText = embedded.getText();

      const tabStopChar = formatParams.insertSpaces ? ' '.repeat(formatParams.tabSize) : '\t';

      // Note that this would have been `document.eol` ideally
      const newLineChar = inputText.includes('\r\n') ? '\r\n' : '\n';

      // Determine the base indentation for the multi-line Stylus content
      let baseIndent = '';
      if (range.start.line !== range.end.line) {
        const styleTagLine = document.getText().split(/\r?\n/)[range.start.line];
        if (styleTagLine) {
          baseIndent = _.get(styleTagLine.match(/^(\t|\s)+/), '0', '');
        }
      }

      // Add one more indentation when `vetur.format.styleInitialIndent` is set to `true`
      if (baseIndentShifted) {
        baseIndent += tabStopChar;
      }

      // Build the formatting options for Stylus Supremacy
      // See https://thisismanta.github.io/stylus-supremacy/#options
      const stylusSupremacyFormattingOptions = StylusSupremacy.createFormattingOptions(config.stylusSupremacy || {});
      const formattingOptions = {
        ...stylusSupremacyFormattingOptions,
        tabStopChar,
        newLineChar: '\n'
      };

      const formattedText = StylusSupremacy.format(inputText, formattingOptions);

      // Add the base indentation and correct the new line characters
      const outputText = ((range.start.line !== range.end.line ? '\n' : '') + formattedText)
        .split(/\n/)
        .map(line => (line.length > 0 ? baseIndent + line : ''))
        .join(newLineChar);

      return [TextEdit.replace(range, outputText)];
    }
  };
}
开发者ID:tiravata,项目名称:vetur,代码行数:97,代码来源:index.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap