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


TypeScript vscode-languageserver.TextDocument类代码示例

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


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

示例1: getEOL

function getEOL(document: TextDocument): string {
	let text = document.getText();
	if (document.lineCount > 1) {
		let to = document.offsetAt(Position.create(1, 0));
		let from = to;
		while (from > 0 && isEOL(text, from - 1)) {
			from--;
		}
		return text.substr(from, to - from);
	}
	return '\n';
}
开发者ID:DiLRandI,项目名称:vscode,代码行数:12,代码来源:jsonFormatter.ts

示例2: syntaxCheck

export async function syntaxCheck(document: TextDocument) {
  const diagnostics: Diagnostic[] = []
  try {
    const client = await clientFromUrl(document.uri)
    if (!client) return
    const obj = await getObject(document.uri)
    // no object or include without a main program
    if (!obj || !objectIsValid(obj)) return

    const source = document.getText()
    const checks = await client.syntaxCheck(
      obj.url,
      obj.mainUrl,
      source,
      obj.mainProgram
    )
    checks.forEach(c => {
      const range = sourceRange(document, c.line, c.offset)
      diagnostics.push({
        message: c.text,
        range,
        severity: decodeSeverity(c.severity)
      })
    })
  } catch (e) {
    log("Exception in syntax check:", e.toString()) // ignore
  }
  connection.sendDiagnostics({ uri: document.uri, diagnostics })
}
开发者ID:valdirmendesgt,项目名称:vscode_abap_remote_fs,代码行数:29,代码来源:syntaxcheck.ts

示例3: validateTextDocumentAsync

export function validateTextDocumentAsync(textDocument: TextDocument, options: CSpellUserSettings): Rx.Observable<Diagnostic> {
    const limit = (options.checkLimit || defaultCheckLimit) * 1024;
    const text = textDocument.getText().slice(0, limit);
    return Rx.Observable.fromPromise<cspell.TextOffset[]>(validateText(text, options))
        .flatMap(a => a)
        .filter(a => !!a)
        .map(a => a!)
        // Convert the offset into a position
        .map(offsetWord => ({...offsetWord, position: textDocument.positionAt(offsetWord.offset) }))
        // Calculate the range
        .map(word => ({
            ...word,
            range: {
                start: word.position,
                end: ({...word.position, character: word.position.character + word.text.length })
            }
        }))
        // Convert it to a Diagnostic
        .map(({text, range}) => ({
            severity: DiagnosticSeverity.Information,
            range: range,
            message: `Unknown word: "${text}"`,
            source: diagSource
        }))
    ;
}
开发者ID:AlekSi,项目名称:vscode-spell-checker,代码行数:26,代码来源:validator.ts

示例4: validateTextDocumentAsync

export function validateTextDocumentAsync(textDocument: TextDocument, options: CSpellUserSettings): Observable<Diagnostic> {
    const { diagnosticLevel = DiagnosticSeverity.Information.toString() } = options;
    const severity = diagSeverityMap.get(diagnosticLevel.toLowerCase()) || DiagnosticSeverity.Information;
    const limit = (options.checkLimit || defaultCheckLimit) * 1024;
    const text = textDocument.getText().slice(0, limit);
    return from(validateText(text, options)).pipe(
        flatMap(a => a),
        filter(a => !!a),
        map(a => a!),
        // Convert the offset into a position
        map(offsetWord => ({...offsetWord, position: textDocument.positionAt(offsetWord.offset) })),
        // Calculate the range
        map(word => ({
            ...word,
            range: {
                start: word.position,
                end: ({...word.position, character: word.position.character + word.text.length })
            }
        })),
        // Convert it to a Diagnostic
        map(({text, range}) => ({
            severity,
            range: range,
            message: `"${text}": Unknown word.`,
            source: diagSource
        })),
    );
}
开发者ID:Jason-Rev,项目名称:vscode-spell-checker,代码行数:28,代码来源:validator.ts

示例5: nodeMcuSignatureHelpHandler

export function nodeMcuSignatureHelpHandler(remoteConsole: RemoteConsole, document: TextDocument, textDocumentPosition: TextDocumentPositionParams): SignatureHelp {
    remoteConsole.log("Server nodeMcuSignatureHelpHandler entered");

    let text = document.getText();
    let lineText = text.split(/\r?\n/g)[textDocumentPosition.position.line];

    let analyzeResult = analyze(lineText, textDocumentPosition.position);

    remoteConsole.log("Server nodeMcuSignatureHelpHandler word: " + JSON.stringify(analyzeResult));

    if (analyzeResult.inSignatureDefinition &&  analyzeResult.signatureName && analyzeResult.moduleName && api[analyzeResult.moduleName]) {
        let currentApi: CompletionItem[] = api[analyzeResult.moduleName];

        let filtered = currentApi.filter(function (value: CompletionItem, index: number, array: CompletionItem[]) {
            return value.label == analyzeResult.signatureName;
        });

        if (filtered.length > 0) {

            let signatureInfo: SignatureInformation = {
                label: filtered[0].detail,
                documentation: filtered[0].documentation
            };

            let result: SignatureHelp = {
                signatures: [signatureInfo],
            };

            return result;
        }
    }

    return null;
}
开发者ID:fduman,项目名称:vscode-nodemcu,代码行数:34,代码来源:nodeMcuSignatureHelpHandler.ts

示例6: assertStyleSheet

function assertStyleSheet(input: string, ...rules: Rule[]): void {
	let p = new Parser();
	let document = TextDocument.create('test://test/test.css', 'css', 0, input);
	let node = p.parseStylesheet(document);

	assertEntries(node, rules);
}
开发者ID:robspassky,项目名称:vscode,代码行数:7,代码来源:lint.test.ts

示例7: assertColor

export function assertColor(parser: Parser, text: string, selection: string, isColor: boolean): void {
	let document = TextDocument.create('test://test/test.css', 'css', 0, text);
	let stylesheet = parser.parseStylesheet(document);
	assert.equal(0, nodes.ParseErrorCollector.entries(stylesheet).length, 'compile errors');

	let node = nodes.getNodeAtOffset(stylesheet, text.indexOf(selection));

	assert.equal(isColor, languageFacts.isColorValue(node));
}
开发者ID:robspassky,项目名称:vscode,代码行数:9,代码来源:languageFacts.test.ts

示例8: getOutline

	function getOutline(value: string): Promise<SymbolInformation[]> {
		var uri = 'test://test.json';

		var symbolProvider = new JSONDocumentSymbols();

		var document = TextDocument.create(uri, 'json', 0, value);
		var jsonDoc = Parser.parse(value);
		return symbolProvider.findDocumentSymbols(document, jsonDoc);
	}
开发者ID:DiLRandI,项目名称:vscode,代码行数:9,代码来源:documentSymbols.test.ts

示例9:

	sortedEdits.forEach(e => {
		let startOffset = document.offsetAt(e.range.start);
		let endOffset = document.offsetAt(e.range.end);
		assert.ok(startOffset <= endOffset);
		assert.ok(endOffset <= lastOffset);
		formatted = formatted.substring(0, startOffset) + e.newText + formatted.substring(endOffset, formatted.length);
		lastOffset = startOffset;
	});
开发者ID:Huachao,项目名称:vscode,代码行数:8,代码来源:textEditSupport.ts

示例10: modifyRange

	// If the selection range just has whitespace before it in the line,
	// extend the range to account for that whitespace
	private modifyRange() {
		const { start } = this.range;
		const offset = this.document.offsetAt(start);
		const prefixLineText = this.originalText.substring(offset - start.character, offset);

		if (/^\s+$/.test(prefixLineText)) {
			this.range.start.character = 0;
		}
	}
开发者ID:rubyide,项目名称:vscode-ruby,代码行数:11,代码来源:BaseFormatter.ts


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