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