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


TypeScript TextDocument.getText方法代碼示例

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


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

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

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

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

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

 function getSettings(doc: TextDocument): [CSpellUserSettings, Promise<SpellingDictionary>] {
     const cached = settingsCache.get(doc.uri);
     if (!cached || cached.version !== doc.version) {
         const docSetting = cspell.constructSettingsForText(fnSettings(), doc.getText(), doc.languageId);
         const dict = cspell.getDictionary(docSetting);
         settingsCache.set(doc.uri, { version: doc.version, settings: [docSetting, dict] });
     }
     return settingsCache.get(doc.uri)!.settings;
 }
開發者ID:AlekSi,項目名稱:vscode-spell-checker,代碼行數:9,代碼來源:codeActions.ts

示例6: constructor

	constructor(document: TextDocument, config: FormatterConfig) {
		this.document = document;
		this.originalText = document.getText();
		this.config = config;
		this.differ = new DiffMatchPatch();

		if (this.range) {
			this.modifyRange();
		}
	}
開發者ID:rubyide,項目名稱:vscode-ruby,代碼行數:10,代碼來源:BaseFormatter.ts

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

示例8: collectEntries

async function collectEntries(
    document: TextDocument,
    request: ImageInfoRequest,
    cancellationToken: CancellationToken
): Promise<ImageInfo[]> {
    let items = [];

    absoluteUrlMappers.forEach(absoluteUrlMapper =>
        absoluteUrlMapper.refreshConfig(request.workspaceFolder, request.additionalSourcefolder, request.paths)
    );

    const lines = document.getText().split(/\r\n|\r|\n/);
    for (const lineIndex of request.visibleLines) {
        var line = lines[lineIndex];
        if (!line) continue;
        if (cancellationToken.isCancellationRequested) return items;
        if (line.length > 20000) {
            continue;
        }

        recognizers
            .map(recognizer => {
                if (cancellationToken.isCancellationRequested) return;
                return recognizer.recognize(lineIndex, line);
            })
            .filter(item => !!item)
            .forEach(urlMatches => {
                if (cancellationToken.isCancellationRequested) return;
                urlMatches.forEach(urlMatch => {
                    if (cancellationToken.isCancellationRequested) return;
                    let absoluteUrls = absoluteUrlMappers
                        .map(mapper => {
                            try {
                                return mapper.map(request.fileName, urlMatch.url);
                            } catch (e) {}
                        })
                        .filter(item => nonNullOrEmpty(item));

                    let absoluteUrlsSet = new Set(absoluteUrls);

                    items = items.concat(
                        Array.from(absoluteUrlsSet.values()).map(absoluteImagePath => {
                            const result =
                                convertToLocalImagePath(absoluteImagePath, urlMatch) || Promise.resolve(null);
                            return result.catch(p => null);
                        })
                    );
                });
            });
    }
    return await Promise.all(items);
}
開發者ID:kisstkondoros,項目名稱:gutter-preview,代碼行數:52,代碼來源:server.ts

示例9: applyEdits

export function applyEdits(document: TextDocument, edits: TextEdit[]) : string {
	let formatted = document.getText();
	let sortedEdits = edits.sort((a, b) => document.offsetAt(b.range.start) - document.offsetAt(a.range.start));
	let lastOffset = formatted.length;
	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;
	});
	return formatted;
}
開發者ID:Huachao,項目名稱:vscode,代碼行數:14,代碼來源:textEditSupport.ts

示例10: async

export const exportDocument = async (
  argdownEngine: AsyncArgdownApplication,
  args: ExportDocumentArgs,
  doc: TextDocument | undefined
) => {
  let request: any = { logLevel: "none" };
  request.inputPath = Uri.parse(args.source).fsPath;
  request.outputPath = Uri.parse(args.target).fsPath;
  const getRequest = requestProviders[args.process];
  request = getRequest(request);
  if (doc) {
    request.input = doc.getText();
    await argdownEngine.runAsync(request);
  } else {
    await argdownEngine.load(request);
  }
};
開發者ID:christianvoigt,項目名稱:argdown,代碼行數:17,代碼來源:Export.ts


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