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


TypeScript TextDocument.getText方法代码示例

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


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

示例1: createDiagnosis

export function createDiagnosis(
    doc: TextDocument,
    fileProcessor: FileProcessor<StylableMeta>,
    requireModule: typeof require
): Diagnostic[] {
    if (!doc.uri.endsWith('.st.css')) {
        return [];
    }
    const file = fromVscodePath(doc.uri);

    const transformer = new StylableTransformer({
        diagnostics: new Diagnostics(),
        fileProcessor,
        requireModule
    });

    const docPostCSSRoot = safeParse(doc.getText(), { from: path.resolve(file) });
    const meta = process(docPostCSSRoot);

    fileProcessor.add(file, meta);

    try {
        transformer.transform(meta);
    } catch { /**/ }
    return meta.diagnostics.reports
        .concat(meta.transformDiagnostics ? meta.transformDiagnostics.reports : [])
        .map(reportToDiagnostic);

    // stylable diagnostic to protocol diagnostic
    function reportToDiagnostic(report: StylableDiagnostic) {
        const severity = report.type === 'error' ? 1 : 2;
        const range = createRange(report);
        return Diagnostic.create(range, report.message, severity);
    }
}
开发者ID:wix,项目名称:stylable-intelligence,代码行数:35,代码来源:diagnosis.ts

示例2: provideCompletionItems

export function provideCompletionItems(document: TextDocument, position: Position): CompletionList {
  const start = document.offsetAt(Position.create(position.line, 0));
  const end = document.offsetAt(position);
  const text = document.getText();
  const currentWord = text.slice(start, end).trim();
  const value = isValue(cssSchema, currentWord);

  let completions: CompletionItem[] = [];

  if (value) {
    const values = getValues(cssSchema, currentWord);
    const symbols = getAllSymbols(text, currentWord, position).filter(
      item => item.kind === CompletionItemKind.Variable || item.kind === CompletionItemKind.Function
    );
    completions = completions.concat(values, symbols, builtIn);
  } else {
    const atRules = getAtRules(cssSchema, currentWord);
    const properties = getProperties(cssSchema, currentWord, false);
    const symbols = getAllSymbols(text, currentWord, position).filter(
      item => item.kind !== CompletionItemKind.Variable
    );
    completions = completions.concat(properties, atRules, symbols);
  }
  return {
    isIncomplete: false,
    items: completions
  };
}
开发者ID:tiravata,项目名称:vetur,代码行数:28,代码来源:completion-item.ts

示例3: stylusHover

export function stylusHover(document: TextDocument, position: Position): Hover {
  const ast = buildAst(document.getText());
  if (!ast) {
    return {
      contents: ''
    };
  }
  const node = findNodeAtPosition(ast, position);
  if (!node) {
    return {
      contents: 'no node found!'
    };
  }

  if (node.__type === 'Property') {
    const property = node.segments[0].name;
    const properties = cssSchema.data.css.properties;
    const item = _.find(properties, item => item.name === property);
    const lineno = node.lineno - 1;
    const column = node.column;
    return {
      contents: (item && item.desc) || 'unknown property',
      range: Range.create(lineno, column, lineno, column + properties.length)
    };
  }
  return {
    contents: []
  };
}
开发者ID:cryptobuks,项目名称:tandem,代码行数:29,代码来源:stylus-hover.ts

示例4: function

	let assertLink = function (links: DocumentLink[], expected: ItemDescription, document: TextDocument) {
		let matches = links.filter(link => {
			return document.offsetAt(link.range.start) === expected.offset;
		});

		assert.equal(matches.length, 1, `${expected.offset} should only existing once: Actual: ${links.map(l => document.offsetAt(l.range.start)).join(', ')}`);
		let match = matches[0];
		assert.equal(document.getText(match.range), expected.value);
		assert.equal(match.target, expected.target);
	};
开发者ID:PKRoma,项目名称:vscode,代码行数:10,代码来源:links.test.ts

示例5: doValidation

export function doValidation(document: TextDocument, engine: CLIEngine): Diagnostic[] {
  const rawText = document.getText();
  // skip checking on empty template
  if (rawText.replace(/\s/g, '') === '') {
    return [];
  }
  const text = rawText.replace(/ {10}/, '<template>') + '</template>';
  const report = engine.executeOnText(text, document.uri);

  return report.results[0] ? report.results[0].messages.map(toDiagnostic) : [];
}
开发者ID:tiravata,项目名称:vetur,代码行数:11,代码来源:htmlValidation.ts

示例6: getTagNameRange

function getTagNameRange(tokenType: TokenType, document: TextDocument, startOffset: number): Range | null {
  const scanner = createScanner(document.getText(), startOffset);
  let token = scanner.scan();
  while (token !== TokenType.EOS && token !== tokenType) {
    token = scanner.scan();
  }
  if (token !== TokenType.EOS) {
    return { start: document.positionAt(scanner.getTokenOffset()), end: document.positionAt(scanner.getTokenEnd()) };
  }
  return null;
}
开发者ID:cryptobuks,项目名称:tandem,代码行数:11,代码来源:htmlHighlighting.ts

示例7: provideDocumentSymbols

export function provideDocumentSymbols(document: TextDocument): SymbolInformation[] {
  const text = document.getText();
  const ast = buildAst(text);
  if (!ast) {
    return [];
  }
  const rawSymbols = _.compact(flattenAndFilterAst(ast));
  const symbolInfos = processRawSymbols(rawSymbols, text.split('\n'));

  return _.uniqBy(symbolInfos, _buildHashFromSymbol);
}
开发者ID:cryptobuks,项目名称:tandem,代码行数:11,代码来源:symbols-finder.ts

示例8: getEmbeddedDocument

function getEmbeddedDocument(document: TextDocument, contents: EmbeddedRegion[], languageId: string): TextDocument {
  const oldContent = document.getText();
  let result = '';
  for (const c of contents) {
    if (c.languageId === languageId) {
      result = oldContent.substring(0, c.start).replace(/./g, ' ');
      result += oldContent.substring(c.start, c.end);
      break;
    }
  }
  return TextDocument.create(document.uri, languageId, document.version, result);
}
开发者ID:cryptobuks,项目名称:tandem,代码行数:12,代码来源:embeddedSupport.ts

示例9: getValueAndRange

function getValueAndRange(document: TextDocument, currRange: Range): { value: string; range: Range } {
  let value = document.getText();
  let range = currRange;

  if (currRange) {
    const startOffset = document.offsetAt(currRange.start);
    const endOffset = document.offsetAt(currRange.end);
    value = value.substring(startOffset, endOffset);
  } else {
    range = Range.create(Position.create(0, 0), document.positionAt(value.length));
  }
  return { value, range };
}
开发者ID:cryptobuks,项目名称:tandem,代码行数:13,代码来源:index.ts

示例10: applyEdits

function applyEdits(document: TextDocument, edits: TextEdit[]): string {
  let text = document.getText();
  const sortedEdits = edits.sort((a, b) => document.offsetAt(b.range.start) - document.offsetAt(a.range.start));
  let lastOffset = text.length;
  sortedEdits.forEach(e => {
    const startOffset = document.offsetAt(e.range.start);
    const endOffset = document.offsetAt(e.range.end);
    assert.ok(startOffset <= endOffset);
    assert.ok(endOffset <= lastOffset);
    text = text.substring(0, startOffset) + e.newText + text.substring(endOffset, text.length);
    lastOffset = startOffset;
  });
  return text;
}
开发者ID:tiravata,项目名称:vetur,代码行数:14,代码来源:completion-test-util.ts


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