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


TypeScript vscode-languageserver-protocol.TextDocument类代码示例

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


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

示例1: while

 lines.forEach((line, ind) => {
     const valueRegex = /value\(([\w-]+)\)/g;
     let regexResult;
     while ((regexResult = valueRegex.exec(line)) !== null) {
         const result = regexResult[1];
         const sym = meta.mappedSymbols[result];
         let color: Color | null = null;
         if (sym && sym._kind === 'var') {
             const doc = TextDocument.create(
                 '',
                 'css',
                 0,
                 '.gaga {border: ' + evalDeclarationValue(stylable.resolver, sym.text, meta, sym.node) + '}'
             );
             color = cssService.findColor(doc);
         } else if (sym && sym._kind === 'import' && sym.type === 'named') {
             const impMeta = processor.process(sym.import.from);
             const relevantVar = impMeta.vars.find(v => v.name === sym.name);
             if (relevantVar) {
                 const doc = TextDocument.create(
                     '',
                     'css',
                     0,
                     '.gaga {border: ' +
                         evalDeclarationValue(
                             stylable.resolver,
                             'value(' + sym.name + ')',
                             impMeta,
                             relevantVar.node
                         ) +
                         '}'
                 );
                 color = cssService.findColor(doc);
             }
         }
         if (color) {
             const range = new ProviderRange(
                 new ProviderPosition(
                     ind,
                     regexResult.index + regexResult[0].indexOf(regexResult[1]) - 'value('.length
                 ),
                 new ProviderPosition(
                     ind,
                     regexResult.index + regexResult[0].indexOf(regexResult[1]) + result.length
                 )
             );
             colorComps.push({ color, range } as ColorInformation);
         }
     }
 });
开发者ID:wix,项目名称:stylable-intelligence,代码行数:50,代码来源:color-provider.ts

示例2: getContentChanges

export function getContentChanges(document: TextDocument, content: string): TextDocumentContentChangeEvent[] {
  let result = fastDiff(document.getText(), content)
  let curr = 0
  let edits: TextDocumentContentChangeEvent[] = []
  for (let i = 0; i < result.length; i++) {
    let item = result[i]
    let [type, content] = item
    if (type == fastDiff.EQUAL) {
      curr += content.length
      continue
    }
    if (type == fastDiff.DELETE) {
      let next = result[i + 1]
      let range: Range = {
        start: document.positionAt(curr),
        end: document.positionAt(curr + content.length)
      }
      curr += content.length
      if (!next || next[0] == fastDiff.EQUAL) {
        edits.push({
          range,
          rangeLength: content.length,
          text: ''
        })
      } else {
        // replace
        i = i + 1
        edits.push({
          range,
          rangeLength: content.length,
          text: next[1]
        })
      }
    } else {
      // add
      let range: Range = {
        start: document.positionAt(curr),
        end: document.positionAt(curr)
      }
      edits.push({
        range,
        rangeLength: 0,
        text: content
      })
    }
  }
  return edits
}
开发者ID:demelev,项目名称:coc.nvim,代码行数:48,代码来源:diff.ts

示例3: getColorPresentation

export function getColorPresentation(
    cssService: CssService,
    document: TextDocument,
    params: ColorPresentationParams
): ColorPresentation[] {
    const src = document.getText();
    const res = fixAndProcess(src, new ProviderPosition(0, 0), params.textDocument.uri);
    const meta = res.processed.meta!;

    const word = src
        .split('\n')
        [params.range.start.line].slice(params.range.start.character, params.range.end.character);
    if (word.startsWith('value(')) {
        return [];
    }

    const wordStart = new ProviderPosition(params.range.start.line + 1, params.range.start.character + 1);
    let noPicker = false;
    meta.rawAst.walkDecls(valueMapping.named, node => {
        if (
            node &&
            ((wordStart.line === node.source!.start!.line && wordStart.character >= node.source!.start!.column) ||
                wordStart.line > node.source!.start!.line) &&
            ((wordStart.line === node.source!.end!.line && wordStart.character <= node.source!.end!.column) ||
                wordStart.line < node.source!.end!.line)
        ) {
            noPicker = true;
        }
    });
    if (noPicker) {
        return [];
    }
    return cssService.getColorPresentations(document, params.color, params.range);
}
开发者ID:wix,项目名称:stylable-intelligence,代码行数:34,代码来源:color-provider.ts

示例4: convertToTextDocumentItem

export function convertToTextDocumentItem(document: TextDocument): TextDocumentItem {
  return {
    uri: document.uri,
    languageId: document.languageId,
    version: document.version,
    text: document.getText()
  }
}
开发者ID:demelev,项目名称:coc.nvim,代码行数:8,代码来源:converter.ts

示例5: asSaveTextDocumentParams

export function asSaveTextDocumentParams(document: TextDocument, includeText: boolean): DidSaveTextDocumentParams {
  let result: DidSaveTextDocumentParams = {
    textDocument: asVersionedTextDocumentIdentifier(document)
  }
  if (includeText) {
    result.text = document.getText()
  }
  return result
}
开发者ID:demelev,项目名称:coc.nvim,代码行数:9,代码来源:converter.ts

示例6: asChangeTextDocumentParams

export function asChangeTextDocumentParams(document: TextDocument): DidChangeTextDocumentParams {
  let result: DidChangeTextDocumentParams = {
    textDocument: {
      uri: document.uri,
      version: document.version
    },
    contentChanges: [{ text: document.getText() }]
  }
  return result
}
开发者ID:demelev,项目名称:coc.nvim,代码行数:10,代码来源:converter.ts

示例7: ProviderPosition

            vars.forEach(v => {
                const doc = TextDocument.create(
                    '',
                    'css',
                    0,
                    '.gaga {border: ' + evalDeclarationValue(stylable.resolver, v.text, impMeta!, v.node) + '}'
                );
                const color = cssService.findColor(doc);
                if (color) {
                    meta.rawAst.walkDecls(valueMapping.named, decl => {
                        const lines = decl.value.split('\n');
                        const reg = new RegExp('\\b' + v.name + '\\b', 'g');

                        const lineIndex = lines.findIndex(l => reg.test(l));
                        if (lineIndex > -1 && lines[lineIndex].indexOf(v.name) > -1) {
                            let extraLines = 0;
                            let extraChars = 0;
                            if (decl.raws.between) {
                                extraLines = decl.raws.between.split('\n').length - 1;
                                extraChars = last(decl.raws.between.split('\n'))!.length;
                            }
                            const varStart = lineIndex // replace with value parser
                                ? lines[lineIndex].indexOf(v.name) // replace with regex
                                : extraLines
                                ? lines[lineIndex].indexOf(v.name) + extraChars
                                : lines[lineIndex].indexOf(v.name) +
                                  valueMapping.named.length +
                                  decl.source!.start!.column +
                                  extraChars -
                                  1;
                            const range = new ProviderRange(
                                new ProviderPosition(decl.source!.start!.line - 1 + lineIndex + extraLines, varStart),
                                new ProviderPosition(
                                    decl.source!.start!.line - 1 + lineIndex + extraLines,
                                    v.name.length + varStart
                                )
                            );
                            colorComps.push({ color, range } as ColorInformation);
                        }
                    });
                }
            });
开发者ID:wix,项目名称:stylable-intelligence,代码行数:42,代码来源:color-provider.ts

示例8: createDocument

 function createDocument(): TextDocument {
   return TextDocument.create('file:///1', 'css', 1, '')
 }
开发者ID:demelev,项目名称:coc.nvim,代码行数:3,代码来源:converter.test.ts

示例9: convertErrors

export function convertErrors(uri: string, content: string, errors: ParseError[]): ErrorItem[] {
  let items: ErrorItem[] = []
  let document = TextDocument.create(uri, 'json', 0, content)
  for (let err of errors) {
    let msg = 'parse error'
    switch (err.error) {
      case 2:
        msg = 'invalid number'
        break
      case 8:
        msg = 'close brace expected'
        break
      case 5:
        msg = 'colon expected'
        break
      case 6:
        msg = 'comma expected'
        break
      case 9:
        msg = 'end of file expected'
        break
      case 16:
        msg = 'invaliad character'
        break
      case 10:
        msg = 'invalid commment token'
        break
      case 15:
        msg = 'invalid escape character'
        break
      case 1:
        msg = 'invalid symbol'
        break
      case 14:
        msg = 'invalid unicode'
        break
      case 3:
        msg = 'property name expected'
        break
      case 13:
        msg = 'unexpected end of number'
        break
      case 12:
        msg = 'unexpected end of string'
        break
      case 11:
        msg = 'unexpected end of comment'
        break
      case 4:
        msg = 'value expected'
        break
      default:
        msg = 'Unknwn error'
        break
    }
    let range: Range = {
      start: document.positionAt(err.offset),
      end: document.positionAt(err.offset + err.length),
    }
    let loc = Location.create(uri, range)
    items.push({ location: loc, message: msg })
  }
  return items
}
开发者ID:illarionvk,项目名称:dotfiles,代码行数:64,代码来源:util.ts

示例10: resolveDocumentColors

export function resolveDocumentColors(stylable: Stylable, cssService: CssService, document: TextDocument) {
    const processor = stylable.fileProcessor;
    const src = document.getText();
    const res = fixAndProcess(src, new ProviderPosition(0, 0), document.uri);
    const meta = res.processed.meta;

    const colorComps: ColorInformation[] = [];

    if (meta) {
        const lines = src.split('\n');
        lines.forEach((line, ind) => {
            const valueRegex = /value\(([\w-]+)\)/g;
            let regexResult;
            while ((regexResult = valueRegex.exec(line)) !== null) {
                const result = regexResult[1];
                const sym = meta.mappedSymbols[result];
                let color: Color | null = null;
                if (sym && sym._kind === 'var') {
                    const doc = TextDocument.create(
                        '',
                        'css',
                        0,
                        '.gaga {border: ' + evalDeclarationValue(stylable.resolver, sym.text, meta, sym.node) + '}'
                    );
                    color = cssService.findColor(doc);
                } else if (sym && sym._kind === 'import' && sym.type === 'named') {
                    const impMeta = processor.process(sym.import.from);
                    const relevantVar = impMeta.vars.find(v => v.name === sym.name);
                    if (relevantVar) {
                        const doc = TextDocument.create(
                            '',
                            'css',
                            0,
                            '.gaga {border: ' +
                                evalDeclarationValue(
                                    stylable.resolver,
                                    'value(' + sym.name + ')',
                                    impMeta,
                                    relevantVar.node
                                ) +
                                '}'
                        );
                        color = cssService.findColor(doc);
                    }
                }
                if (color) {
                    const range = new ProviderRange(
                        new ProviderPosition(
                            ind,
                            regexResult.index + regexResult[0].indexOf(regexResult[1]) - 'value('.length
                        ),
                        new ProviderPosition(
                            ind,
                            regexResult.index + regexResult[0].indexOf(regexResult[1]) + result.length
                        )
                    );
                    colorComps.push({ color, range } as ColorInformation);
                }
            }
        });

        meta.imports.forEach(imp => {
            let impMeta: StylableMeta | undefined;
            try {
                impMeta = processor.process(imp.from);
            } catch { /**/ }

            if (!impMeta) {
                return;
            }

            const vars = impMeta.vars;
            vars.forEach(v => {
                const doc = TextDocument.create(
                    '',
                    'css',
                    0,
                    '.gaga {border: ' + evalDeclarationValue(stylable.resolver, v.text, impMeta!, v.node) + '}'
                );
                const color = cssService.findColor(doc);
                if (color) {
                    meta.rawAst.walkDecls(valueMapping.named, decl => {
                        const lines = decl.value.split('\n');
                        const reg = new RegExp('\\b' + v.name + '\\b', 'g');

                        const lineIndex = lines.findIndex(l => reg.test(l));
                        if (lineIndex > -1 && lines[lineIndex].indexOf(v.name) > -1) {
                            let extraLines = 0;
                            let extraChars = 0;
                            if (decl.raws.between) {
                                extraLines = decl.raws.between.split('\n').length - 1;
                                extraChars = last(decl.raws.between.split('\n'))!.length;
                            }
                            const varStart = lineIndex // replace with value parser
                                ? lines[lineIndex].indexOf(v.name) // replace with regex
                                : extraLines
                                ? lines[lineIndex].indexOf(v.name) + extraChars
                                : lines[lineIndex].indexOf(v.name) +
                                  valueMapping.named.length +
                                  decl.source!.start!.column +
//.........这里部分代码省略.........
开发者ID:wix,项目名称:stylable-intelligence,代码行数:101,代码来源:color-provider.ts


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