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


TypeScript TextDocument.positionAt方法代碼示例

本文整理匯總了TypeScript中vscode.TextDocument.positionAt方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript TextDocument.positionAt方法的具體用法?TypeScript TextDocument.positionAt怎麽用?TypeScript TextDocument.positionAt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在vscode.TextDocument的用法示例。


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

示例1: getWindowsLineEndingCount

export function getWindowsLineEndingCount(document: TextDocument, offset: Number) {
    const eolPattern = new RegExp('\r\n', 'g');
    const readBlock = 1024;
    let count = 0;
    let offsetDiff = offset.valueOf();

    // In order to prevent the one-time loading of large files from taking up too much memory
    for (let pos = 0; pos < offset; pos += readBlock) {
        let startAt = document.positionAt(pos);
        let endAt = null;

        if (offsetDiff >= readBlock) {
            endAt = document.positionAt(pos + readBlock);
            offsetDiff = offsetDiff - readBlock;
        } else {
            endAt = document.positionAt(pos + offsetDiff);
        }

        let text = document.getText(new Range(startAt, endAt));
        let cr = text.match(eolPattern);

        count += cr ? cr.length : 0;
    }
    return count;
}
開發者ID:,項目名稱:,代碼行數:25,代碼來源:

示例2: provideCompletionItems

	public provideCompletionItems(document: TextDocument, position: Position, token: CancellationToken): Thenable<CompletionList> {

		let fileName = basename(document.fileName);

		let currentWord = this.getCurrentWord(document, position);
		let overwriteRange : Range;

		let items: CompletionItem[] = [];
		let isIncomplete = false;

		let offset = document.offsetAt(position);
		let location = getLocation(document.getText(), offset);

		let node = location.previousNode;
		if (node && node.offset <= offset && offset <= node.offset + node.length && (node.type === 'property' || node.type === 'string' || node.type === 'number' || node.type === 'boolean' || node.type === 'null')) {
			overwriteRange = new Range(document.positionAt(node.offset), document.positionAt(node.offset + node.length));
		} else {
			overwriteRange = new Range(document.positionAt(offset - currentWord.length), position);
		}
		let filterText = document.getText(new Range(overwriteRange.start, position));

		let proposed: { [key: string]: boolean } = {};
		let collector: ISuggestionsCollector = {
			add: (suggestion: CompletionItem) => {
				if (!proposed[suggestion.label]) {
					proposed[suggestion.label] = true;
					suggestion.textEdit = TextEdit.replace(overwriteRange, suggestion.insertText);
					suggestion.filterText = filterText;

					items.push(suggestion);
				}
			},
			setAsIncomplete: () => isIncomplete = true,
			error: (message: string) => console.error(message),
			log: (message: string) => console.log(message)
		};

		let collectPromise : Thenable<any> = null;

		if (location.isAtPropertyKey) {
			let addValue = !location.previousNode || !location.previousNode.columnOffset;
			let isLast = this.isLast(document, position);
			collectPromise = this.jsonContribution.collectPropertySuggestions(fileName, location, currentWord, addValue, isLast, collector);
		} else {
			if (location.path.length === 0) {
				collectPromise = this.jsonContribution.collectDefaultSuggestions(fileName, collector);
			} else {
				collectPromise = this.jsonContribution.collectValueSuggestions(fileName, location, collector);
			}
		}
		if (collectPromise) {
			return collectPromise.then(() => {
				if (items.length > 0) {
					return new CompletionList(items, isIncomplete);
				}
				return null;
			});
		}
		return null;
	}
開發者ID:Aarushi-Ign,項目名稱:vscode,代碼行數:60,代碼來源:jsonContributions.ts

示例3: getDiagnostic

function getDiagnostic(document: TextDocument, report: NpmListReport, moduleName: string, ranges: SourceRanges): Diagnostic {
	let diagnostic = null;

	// npm list only reports errors against 'dependencies' and not against 'devDependencies'
	if (report.dependencies && report.dependencies[moduleName]) {
		if (report.dependencies[moduleName]['missing'] === true) {
			if (ranges.dependencies[moduleName]) {
				const source = ranges.dependencies[moduleName].name;
				const range = new Range(document.positionAt(source.offset), document.positionAt(source.offset + source.length));
				diagnostic = new Diagnostic(range, `Module '${moduleName}' is not installed`, DiagnosticSeverity.Warning);
			} else {
				console.log(`[npm-script] Could not locate "missing" dependency '${moduleName}' in package.json`);
			}
		}
		else if (report.dependencies[moduleName]['invalid'] === true) {
			if (ranges.dependencies[moduleName]) {
				const source = ranges.dependencies[moduleName].version;
				const installedVersion = report.dependencies[moduleName]['version'];
				const range = new Range(document.positionAt(source.offset), document.positionAt(source.offset + source.length));
				const message = installedVersion ?
					`Module '${moduleName}' the installed version '${installedVersion}' is invalid` :
					`Module '${moduleName}' the installed version is invalid or has errors`;
				diagnostic = new Diagnostic(range, message, DiagnosticSeverity.Warning);
			} else {
				console.log(`[npm-script] Could not locate "invalid" dependency '${moduleName}' in package.json`);
			}
		}
		else if (report.dependencies[moduleName]['extraneous'] === true) {
			const source = findAttributeRange(ranges);
			const range = new Range(document.positionAt(source.offset), document.positionAt(source.offset + source.length));
			diagnostic = new Diagnostic(range, `Module '${moduleName}' is extraneous`, DiagnosticSeverity.Warning);
		}
	}
	return diagnostic;
}
開發者ID:scytalezero,項目名稱:vscode-npm-scripts,代碼行數:35,代碼來源:main.ts

示例4: buildOccurrences

	private buildOccurrences(
		highlights: DocumentHighlight[], document: TextDocument, position: number, occurrences: as.Occurrences
	) {
		let element = occurrences.element;
		let offsets: number[] = occurrences.offsets;
		let length: number = occurrences.length;

		for (let i = 0; i < offsets.length; i++) {
			let offset = offsets[i];

			// Look for a match in any of the occurance ranges.
			if ((offset <= position) && (position < (offset + length))) {
				// If we get a match, then create highlights for all the items in the matching occurance.
				for (let i = 0; i < offsets.length; i++) {
					let offset = offsets[i];
					let range = new Range(
						document.positionAt(offset),
						document.positionAt(offset + length)
					);
					highlights.push(new DocumentHighlight(range));
				}

				return;
			}
		}
	}
開發者ID:devoncarew,項目名稱:Dart-Code,代碼行數:26,代碼來源:dart_highlighting_provider.ts

示例5: Range

 return bat.errors.filter(x => x.node).map(error => {
   var startPos = doc.positionAt(error.node.startPosition);
   var endPos = doc.positionAt(error.node.endPosition);
   var decoration = {
     range: new Range(startPos, endPos),
     hoverMessage: error.toString()
   };
   return decoration;
 });
開發者ID:mulesoft-labs,項目名稱:http-bat-vscode,代碼行數:9,代碼來源:extension.ts

示例6: getRange

	private getRange(document: TextDocument, outline: as.Outline): Range {
		// The outline's location includes whitespace before the block but the elements
		// location only includes the small range declaring the element. To give the best
		// experience to the user (perfectly highlight the range) we take the start point
		// from the element but the end point from the outline.

		let startPos = document.positionAt(outline.element.location.offset);
		let endPos = document.positionAt(outline.offset + outline.length);

		return new Range(startPos, endPos);
	}
開發者ID:devoncarew,項目名稱:Dart-Code,代碼行數:11,代碼來源:dart_document_symbol_provider.ts

示例7: getTodos

    public static getTodos(doc: TextDocument): model.TodoItem[] {
        let docContent = doc.getText();
        let regex = new rg.RegexFactory(doc.languageId).get();
        /* For no reason, vscode returns duplicates matches sometimes.
        To avoid that, check if a new item exists in the set */
        let set = new collections.Set<model.TodoItem>();
        let results: model.TodoItem[] = [];
        if (docContent != "") {
            let match, indices = [];
            while (match = regex.exec(docContent)) {
                indices.push(match.index);

                let matched_text = (match[1]) ? match[1] : match[0];
                let filter_result = this.filter(this.cleanString(matched_text));
                matched_text = filter_result[0];
                if(!matched_text) { // there is no todo
                    continue;
                }
                let skipped = filter_result[1];
                let id = match.index + skipped;
                let range = new Range(doc.positionAt(id), doc.positionAt(id + matched_text.length));
                let new_item = new model.TodoItem(range, matched_text, doc.fileName);
                
                if (!set.contains(new_item)) {
                    results.push(new_item);
                    set.add(new_item);
                }
            }
        }

        return results;
    }
開發者ID:Iancurtis,項目名稱:vscode-todo-parser,代碼行數:32,代碼來源:todo_parser.ts

示例8: toDecorationRange

 public toDecorationRange(start: number, document: TextDocument): Range {
     const pos = document.positionAt(start);
     const line = pos.line;
     const documentLine = document.lineAt(line);
     const lineRange = documentLine.range;
     return new Range(lineRange.end.line, lineRange.end.character, lineRange.end.line, lineRange.end.character);
 }
開發者ID:kisstkondoros,項目名稱:codemetrics,代碼行數:7,代碼來源:MetricsUtil.ts

示例9: resolve

			}).then(resp => {
				if (resp.hovers.length == 0) {
					resolve(null);
				} else {
					let hover = resp.hovers[0];
					let markdown = this.getHoverData(hover);
					if (markdown) {
						let range = new Range(
							document.positionAt(hover.offset),
							document.positionAt(hover.offset + hover.length)
						);
						resolve(new Hover(markdown, range));
					} else {
						resolve(null);
					}
				}
			});
開發者ID:ikhwanhayat,項目名稱:Dart-Code,代碼行數:17,代碼來源:dart_hover_provider.ts

示例10: Range

		cachedScriptsMap!.forEach((value, key) => {
			let start = document.positionAt(value[0]);
			let end = document.positionAt(value[0] + value[1]);
			let range = new Range(start, end);

			if (range.contains(position)) {
				let contents: MarkdownString = new MarkdownString();
				contents.isTrusted = true;
				contents.appendMarkdown(this.createRunScriptMarkdown(key, document.uri));

				let debugArgs = extractDebugArgFromScript(value[2]);
				if (debugArgs) {
					contents.appendMarkdown(this.createDebugScriptMarkdown(key, document.uri, debugArgs[0], debugArgs[1]));
				}
				hover = new Hover(contents);
			}
		});
開發者ID:developers23,項目名稱:vscode,代碼行數:17,代碼來源:scriptHover.ts


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