當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript vscode-languageserver-types.TextDocument類代碼示例

本文整理匯總了TypeScript中vscode-languageserver-types.TextDocument的典型用法代碼示例。如果您正苦於以下問題:TypeScript TextDocument類的具體用法?TypeScript TextDocument怎麽用?TypeScript TextDocument使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了TextDocument類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: applyEdits

 function applyEdits(oldStr: string, newStr: string): void {
   let doc = TextDocument.create('untitled://1', 'markdown', 0, oldStr)
   let changes = getContentChanges(doc, newStr)
   let res = TextDocument.applyEdits(doc, changes.map(o => {
     return { range: o.range, newText: o.text }
   }))
   expect(res).toBe(newStr)
 }
開發者ID:demelev,項目名稱:coc.nvim,代碼行數:8,代碼來源:diff.test.ts

示例2: 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

示例3: applyEdits

 function applyEdits(oldStr: string, newStr: string): void {
   let doc = TextDocument.create('untitled://1', 'markdown', 0, oldStr)
   let change = getChange(doc.getText(), newStr)
   let start = doc.positionAt(change.start)
   let end = doc.positionAt(change.end)
   let edit: TextEdit = {
     range: { start, end },
     newText: change.newText
   }
   let res = TextDocument.applyEdits(doc, [edit])
   expect(res).toBe(newStr)
 }
開發者ID:illarionvk,項目名稱:dotfiles,代碼行數:12,代碼來源:diff.test.ts

示例4: 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

示例5: 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

示例6: getLanguageRangeByType

function getLanguageRangeByType(
  document: TextDocument,
  contents: EmbeddedRegion[],
  type: EmbeddedType
): LanguageRange | undefined {
  for (const c of contents) {
    if (c.type === type) {
      return {
        start: document.positionAt(c.start),
        end: document.positionAt(c.end),
        languageId: c.languageId
      };
    }
  }
}
開發者ID:tiravata,項目名稱:vetur,代碼行數:15,代碼來源:embeddedSupport.ts

示例7: assertEmbeddedLanguageContent

	function assertEmbeddedLanguageContent(value: string, languageId: string, expectedContent: string): void {
		let document = TextDocument.create('test://test/test.html', 'html', 0, value);

		let docRegions = embeddedSupport.getDocumentRegions(htmlLanguageService, document);
		let content = docRegions.getEmbeddedDocument(languageId);
		assert.equal(content.getText(), expectedContent);
	}
開發者ID:AllureFer,項目名稱:vscode,代碼行數:7,代碼來源:embedded.test.ts

示例8: assertCompletions

	function assertCompletions(syntax: string, value: string, expectedProposal: string, expectedProposalDoc: string): void {
		const offset = value.indexOf('|');
		value = value.substr(0, offset) + value.substr(offset + 1);

		const document = TextDocument.create('test://test/test.' + syntax, syntax, 0, value);
		const position = document.positionAt(offset);
		const documentRegions = getLanguageModelCache<embeddedSupport.HTMLDocumentRegions>(10, 60, document => embeddedSupport.getDocumentRegions(htmlLanguageService, document));
		const mode = syntax == 'html' ? getHTMLMode(htmlLanguageService) : getCSSMode(documentRegions);
		const emmetCompletionList: CompletionList = {
			isIncomplete: true,
			items: undefined
		}
		mode.setCompletionParticipants([getEmmetCompletionParticipants(document, position, document.languageId, {}, emmetCompletionList)])

		const list = mode.doComplete!(document, position);
		assert.ok(list);
		assert.ok(emmetCompletionList)


		if (expectedProposal && expectedProposalDoc) {
			let actualLabels = emmetCompletionList!.items.map(c => c.label).sort();
			let actualDocs = emmetCompletionList!.items.map(c => c.documentation).sort();
			assert.ok(actualLabels.indexOf(expectedProposal) !== -1, 'Not found:' + expectedProposal + ' is ' + actualLabels.join(', '));
			assert.ok(actualDocs.indexOf(expectedProposalDoc) !== -1, 'Not found:' + expectedProposalDoc + ' is ' + actualDocs.join(', '));
		} else {
			assert.ok(!emmetCompletionList || !emmetCompletionList.items);
		}

	}
開發者ID:sameer-coder,項目名稱:vscode,代碼行數:29,代碼來源:emmet.test.ts

示例9:

 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;
 });
開發者ID:tiravata,項目名稱:vetur,代碼行數:8,代碼來源:completion-test-util.ts

示例10:

		const ranges = applicableRanges.map(pair => {
			return {
				range: Range.create(
					document.positionAt(pair[0]),
					document.positionAt(pair[1])
				),
				kind: SelectionRangeKind.Statement
			};
		});
開發者ID:Microsoft,項目名稱:vscode-css-languageservice,代碼行數:9,代碼來源:cssSelectionRange.ts


注:本文中的vscode-languageserver-types.TextDocument類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。