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


TypeScript vscode-languageserver.Range類代碼示例

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


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

示例1: getFoldingRanges

export function getFoldingRanges(languageModes: LanguageModes, document: TextDocument, maxRanges: number | undefined, _cancellationToken: CancellationToken | null): FoldingRange[] {
	let htmlMode = languageModes.getMode('html');
	let range = Range.create(Position.create(0, 0), Position.create(document.lineCount, 0));
	let result: FoldingRange[] = [];
	if (htmlMode && htmlMode.getFoldingRanges) {
		result.push(...htmlMode.getFoldingRanges(document));
	}

	// cache folding ranges per mode
	let rangesPerMode: { [mode: string]: FoldingRange[] } = Object.create(null);
	let getRangesForMode = (mode: LanguageMode) => {
		if (mode.getFoldingRanges) {
			let ranges = rangesPerMode[mode.getId()];
			if (!Array.isArray(ranges)) {
				ranges = mode.getFoldingRanges(document) || [];
				rangesPerMode[mode.getId()] = ranges;
			}
			return ranges;
		}
		return [];
	};

	let modeRanges = languageModes.getModesInRange(document, range);
	for (let modeRange of modeRanges) {
		let mode = modeRange.mode;
		if (mode && mode !== htmlMode && !modeRange.attributeValue) {
			const ranges = getRangesForMode(mode);
			result.push(...ranges.filter(r => r.startLine >= modeRange.start.line && r.endLine < modeRange.end.line));
		}
	}
	if (maxRanges && result.length > maxRanges) {
		result = limitRanges(result, maxRanges);
	}
	return result;
}
開發者ID:PKRoma,項目名稱:vscode,代碼行數:35,代碼來源:htmlFolding.ts

示例2:

export const createRange = (el: HasLocation): Range => {
  return Range.create(
    (el.startLine || 1) - 1,
    (el.startColumn || 1) - 1,
    (el.endLine || 1) - 1,
    el.endColumn || 1
  );
};
開發者ID:christianvoigt,項目名稱:argdown,代碼行數:8,代碼來源:utils.ts

示例3: it

 it ('should return diagnostics with proper range', () => {
     let ghcModOutput = ['A.hs:5:7:Not in scope: `a`'];
     let range = Range.create(4, 6, 4, 6);
     let logger: ILogger = new TestLogger();
     let ghcMod: IGhcMod = new TestGhcMod(ghcModOutput);
     let provider: IGhcModProvider = new GhcModProvider(ghcMod, '', logger);
     return provider.doCheck(null, null, false).then((diagnostics) => {
         assert.deepEqual(diagnostics[0].range, range);
     });
 });
開發者ID:gdziadkiewicz,項目名稱:vscode-ghc-mod,代碼行數:10,代碼來源:ghcModProvider.spec.ts

示例4: getFoldingRanges

export function getFoldingRanges(languageModes: LanguageModes, document: TextDocument, maxRanges: number | undefined, cancellationToken: CancellationToken | null): FoldingRange[] {
	let htmlMode = languageModes.getMode('html');
	let range = Range.create(Position.create(0, 0), Position.create(document.lineCount, 0));
	let ranges: FoldingRange[] = [];
	if (htmlMode && htmlMode.getFoldingRanges) {
		ranges.push(...htmlMode.getFoldingRanges(document, range));
	}
	let modeRanges = languageModes.getModesInRange(document, range);
	for (let modeRange of modeRanges) {
		let mode = modeRange.mode;
		if (mode && mode !== htmlMode && mode.getFoldingRanges && !modeRange.attributeValue) {
			ranges.push(...mode.getFoldingRanges(document, modeRange));
		}
	}
	if (maxRanges && ranges.length > maxRanges) {
		ranges = limitRanges(ranges, maxRanges);
	}
	return ranges;
}
開發者ID:AllureFer,項目名稱:vscode,代碼行數:19,代碼來源:htmlFolding.ts

示例5: format

	function format(unformatted: string, expected: string, insertSpaces = true) {
		let range: Range = null;
		let uri = 'test://test.json';

		let rangeStart = unformatted.indexOf('|');
		let rangeEnd = unformatted.lastIndexOf('|');
		if (rangeStart !== -1 && rangeEnd !== -1) {
			// remove '|'
			var unformattedDoc = ITextDocument.create(uri, unformatted);
			unformatted = unformatted.substring(0, rangeStart) + unformatted.substring(rangeStart + 1, rangeEnd) + unformatted.substring(rangeEnd + 1);
			let startPos = unformattedDoc.positionAt(rangeStart);
			let endPos = unformattedDoc.positionAt(rangeEnd);
			range = Range.create(startPos, endPos);
		}

		var document = ITextDocument.create(uri, unformatted);
		let edits = Formatter.format(document, range, { tabSize: 2, insertSpaces: insertSpaces });
		let formatted  = applyEdits(document, edits);
		assert.equal(formatted, expected);
	}
開發者ID:1833183060,項目名稱:vscode,代碼行數:20,代碼來源:formatter.test.ts

示例6: constructor

    public constructor(type: ext.le_DefinitionObjectType, name: string, path: string,
                       start: loader.Location, end: loader.Location,
                       defaultCollapsed?: boolean)
    {
        let newRange = lsp.Range.create(start.line - 1, start.column, end.line - 1, end.column + 1);

        this.name = name;
        this.kind = type as lsp.SymbolKind;
        this.defPath = Uri.file(path).toString();

        this.range = newRange;
        this.selectionRange = newRange;

        if (defaultCollapsed !== undefined)
        {
            this.defaultCollapsed = true;
        }

        this.children = [];
    }
開發者ID:legatoproject,項目名稱:legato-af,代碼行數:20,代碼來源:vscTypeConvert.ts

示例7:

    lodash.forEach(annotations, (annotation) => {

      const lineReference = refractUtils.createLineReferenceFromSourceMap(
        annotation.attributes.sourceMap,
        text,
        documentLines
      );

      if (!lodash.isEmpty(lineReference)) {
        diagnostics.push({
          severity: ((lodash.head(annotation.meta.classes) === 'warning') ? DiagnosticSeverity.Warning : DiagnosticSeverity.Error),
          code: annotation.attributes.code,
          range: Range.create(
            lineReference.startRow,
            lineReference.startIndex,
            lineReference.endRow,
            lineReference.endIndex
          ),
          message: annotation.content,
          source: parserName
        });
      }
    });
開發者ID:smizell,項目名稱:vscode-apielements,代碼行數:23,代碼來源:server.ts

示例8:

      lodash.forEach(annotations, (annotation) => {

        const lineReference = refractUtils.createLineReferenceFromSourceMap(
          annotation.attributes.sourceMap,
          text,
          documentLines,
        );

        diagnostics.push({
          code: annotation.attributes.code,
          message: annotation.content,
          range: Range.create(
            lineReference.startRow,
            lineReference.startIndex,
            lineReference.endRow,
            lineReference.endIndex,
          ),
          severity: ((lodash.head(annotation.meta.classes) === 'warning')
            ? DiagnosticSeverity.Warning : DiagnosticSeverity.Error),
          source: 'fury',
        } as Diagnostic);

      });
開發者ID:XVincentX,項目名稱:vscode-apielements,代碼行數:23,代碼來源:server.ts

示例9: format

export function format(document: ITextDocument, range: Range, options: FormattingOptions): TextEdit[] {
	const documentText = document.getText();
	let initialIndentLevel: number;
	let value: string;
	let rangeOffset: number;
	if (range) {
		let startPosition = Position.create(range.start.line, 0);
		rangeOffset = document.offsetAt(startPosition);

		let endOffset = document.offsetAt(Position.create(range.end.line + 1, 0));
		let endLineStart = document.offsetAt(Position.create(range.end.line, 0));
		while (endOffset > endLineStart && isEOL(documentText, endOffset - 1)) {
			endOffset--;
		}
		range = Range.create(startPosition, document.positionAt(endOffset));
		value = documentText.substring(rangeOffset, endOffset);
		initialIndentLevel = computeIndentLevel(value, 0, options);
	} else {
		value = documentText;
		range = Range.create(Position.create(0, 0), document.positionAt(value.length));
		initialIndentLevel = 0;
		rangeOffset = 0;
	}
	let eol = getEOL(document);

	let lineBreak = false;
	let indentLevel = 0;
	let indentValue: string;
	if (options.insertSpaces) {
		indentValue = repeat(' ', options.tabSize);
	} else {
		indentValue = '\t';
	}

	let scanner = Json.createScanner(value, false);

	function newLineAndIndent(): string {
		return eol + repeat(indentValue, initialIndentLevel + indentLevel);
	}
	function scanNext(): Json.SyntaxKind {
		let token = scanner.scan();
		lineBreak = false;
		while (token === Json.SyntaxKind.Trivia || token === Json.SyntaxKind.LineBreakTrivia) {
			lineBreak = lineBreak || (token === Json.SyntaxKind.LineBreakTrivia);
			token = scanner.scan();
		}
		return token;
	}
	let editOperations: TextEdit[] = [];
	function addEdit(text: string, startOffset: number, endOffset: number) {
		if (documentText.substring(startOffset, endOffset) !== text) {
			let replaceRange = Range.create(document.positionAt(startOffset), document.positionAt(endOffset));
			editOperations.push(TextEdit.replace(replaceRange, text));
		}
	}

	let firstToken = scanNext();
	if (firstToken !== Json.SyntaxKind.EOF) {
		let firstTokenStart = scanner.getTokenOffset() + rangeOffset;
		let initialIndent = repeat(indentValue, initialIndentLevel);
		addEdit(initialIndent, rangeOffset, firstTokenStart);
	}

	while (firstToken !== Json.SyntaxKind.EOF) {
		let firstTokenEnd = scanner.getTokenOffset() + scanner.getTokenLength() + rangeOffset;
		let secondToken = scanNext();

		let replaceContent = '';
		while (!lineBreak && (secondToken === Json.SyntaxKind.LineCommentTrivia || secondToken === Json.SyntaxKind.BlockCommentTrivia)) {
			// comments on the same line: keep them on the same line, but ignore them otherwise
			let commentTokenStart = scanner.getTokenOffset() + rangeOffset;
			addEdit(' ', firstTokenEnd, commentTokenStart);
			firstTokenEnd = scanner.getTokenOffset() + scanner.getTokenLength() + rangeOffset;
			replaceContent = secondToken === Json.SyntaxKind.LineCommentTrivia ? newLineAndIndent() : '';
			secondToken = scanNext();
		}
		
		if (secondToken === Json.SyntaxKind.CloseBraceToken) {
			if (firstToken !== Json.SyntaxKind.OpenBraceToken) {
				indentLevel--;
				replaceContent = newLineAndIndent();
			}
		} else if (secondToken === Json.SyntaxKind.CloseBracketToken) {
			if (firstToken !== Json.SyntaxKind.OpenBracketToken) {
				indentLevel--;
				replaceContent = newLineAndIndent();
			}
		} else {
			switch (firstToken) {
				case Json.SyntaxKind.OpenBracketToken:
				case Json.SyntaxKind.OpenBraceToken:
					indentLevel++;
					replaceContent = newLineAndIndent();
					break;
				case Json.SyntaxKind.CommaToken:
				case Json.SyntaxKind.LineCommentTrivia:
					replaceContent = newLineAndIndent();
					break;
				case Json.SyntaxKind.BlockCommentTrivia:
					if (lineBreak) {
//.........這裏部分代碼省略.........
開發者ID:13572293130,項目名稱:vscode,代碼行數:101,代碼來源:jsonFormatter.ts

示例10: addEdit

	function addEdit(text: string, startOffset: number, endOffset: number) {
		if (documentText.substring(startOffset, endOffset) !== text) {
			let replaceRange = Range.create(document.positionAt(startOffset), document.positionAt(endOffset));
			editOperations.push(TextEdit.replace(replaceRange, text));
		}
	}
開發者ID:13572293130,項目名稱:vscode,代碼行數:6,代碼來源:jsonFormatter.ts


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