本文整理汇总了TypeScript中vscode-languageserver.IConnection.onRequest方法的典型用法代码示例。如果您正苦于以下问题:TypeScript IConnection.onRequest方法的具体用法?TypeScript IConnection.onRequest怎么用?TypeScript IConnection.onRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vscode-languageserver.IConnection
的用法示例。
在下文中一共展示了IConnection.onRequest方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: pushAll
let document = documents.get(documentSymbolParms.textDocument.uri);
let symbols: SymbolInformation[] = [];
languageModes.getAllModesInDocument(document).forEach(m => {
if (m.findDocumentSymbols) {
pushAll(symbols, m.findDocumentSymbols(document));
}
});
return symbols;
});
connection.onRequest(DocumentColorRequest.type, params => {
let infos: ColorInformation[] = [];
let document = documents.get(params.textDocument.uri);
if (document) {
languageModes.getAllModesInDocument(document).forEach(m => {
if (m.findDocumentColors) {
pushAll(infos, m.findDocumentColors(document));
}
});
}
return infos;
});
connection.onRequest(TagCloseRequest.type, params => {
let document = documents.get(params.textDocument.uri);
if (document) {
let pos = params.position;
if (pos.character > 0) {
let mode = languageModes.getModeAtPosition(document, Position.create(pos.line, pos.character - 1));
if (mode && mode.doAutoClose) {
return mode.doAutoClose(document, pos);
}
示例2: parse
sourcemaps are char based and not byte based.
See https://github.com/apiaryio/fury.js/issues/63 for more details.
*/
}
const documentLines = textDocument.split(/\r?\n/g);
const refractOutput = refractDocuments.get(symbolParam.textDocument.uri.toString());
if (typeof (refractOutput) === 'undefined') {
return parse(textDocument, currentSettings.parser)
.then((output) => {
refractDocuments.set(symbolParam.textDocument.uri.toString(), output);
return refractUtils.extractSymbols(output, textDocument, documentLines, desideredSymbols);
});
}
const symbolArray = refractUtils.extractSymbols(refractOutput, textDocument, documentLines, desideredSymbols);
return Promise.resolve(symbolArray);
} catch (err) {
connection.window.showErrorMessage(err.message);
}
});
connection.onRequest('parserOutput', (code: string) => {
return parse(code, currentSettings.parser);
});
connection.listen();
示例3:
resolveReference: ref => {
if (workspacePath && ref[0] === '/') {
return uri.file(path.join(workspacePath, ref)).toString();
}
return url.resolve(document.uri, ref);
}
};
let links: DocumentLink[] = [];
languageModes.getAllModesInDocument(document).forEach(m => {
if (m.findDocumentLinks) {
links = links.concat(m.findDocumentLinks(document, documentContext));
}
});
return links;
});
connection.onRequest(ColorSymbolRequest.type, uri => {
let ranges: Range[] = [];
let document = documents.get(uri);
if (document) {
languageModes.getAllModesInDocument(document).forEach(m => {
if (m.findColorSymbols) {
ranges = ranges.concat(m.findColorSymbols(document));
}
});
}
return ranges;
});
// Listen on the connection
connection.listen();
示例4: run
function run() {
// debounce buffer
const validationRequestStream = new Rx.ReplaySubject<TextDocument>(1);
const validationFinishedStream = new Rx.ReplaySubject<{ uri: string; version: number }>(1);
const triggerUpdateConfig = new Rx.ReplaySubject<void>(1);
const triggerValidateAll = new Rx.ReplaySubject<void>(1);
// Create a connection for the server. The connection uses Node's IPC as a transport
const connection: IConnection = createConnection(new IPCMessageReader(process), new IPCMessageWriter(process));
g_connection = connection;
log('Start');
// Create a simple text document manager. The text document manager
// supports full document sync only
const documents: TextDocuments = new TextDocuments();
// After the server has started the client sends an initialize request. The server receives
// in the passed params the rootPath of the workspace plus the client capabilities.
let workspaceRoot: string | undefined;
connection.onInitialize((params: InitializeParams, token: CancellationToken): InitializeResult => {
workspaceRoot = params.rootPath || undefined;
return {
capabilities: {
// Tell the client that the server works in FULL text document sync mode
textDocumentSync: documents.syncKind,
codeActionProvider: true
}
};
});
// The settings have changed. Is sent on server activation as well.
connection.onDidChangeConfiguration(onConfigChange);
interface OnChangeParam { settings: Settings; }
function onConfigChange(change: OnChangeParam) {
log('onConfigChange');
Object.assign(vscodeSettings, change.settings || {});
log(`Enabled: ${vscodeSettings.cSpell && vscodeSettings.cSpell.enabled ? 'True' : 'False'}`);
triggerUpdateConfig.next(undefined);
}
function updateActiveSettings() {
log('updateActiveSettings');
CSpell.clearCachedSettings();
const configPaths = workspaceRoot ? [
path.join(workspaceRoot, '.vscode', CSpell.defaultSettingsFilename.toLowerCase()),
path.join(workspaceRoot, '.vscode', CSpell.defaultSettingsFilename),
path.join(workspaceRoot, CSpell.defaultSettingsFilename.toLowerCase()),
path.join(workspaceRoot, CSpell.defaultSettingsFilename),
] : [];
const cSpellSettingsFile = CSpell.readSettingsFiles(configPaths);
const { cSpell = {}, search = {} } = vscodeSettings;
const { exclude = {} } = search;
const importPaths = [...configsToImport.keys()].sort();
const importSettings = CSpell.readSettingsFiles(importPaths);
const mergedSettings = CSpell.mergeSettings(defaultSettings, importSettings, cSpellSettingsFile, cSpell);
const { ignorePaths = []} = mergedSettings;
const globs = defaultExclude.concat(ignorePaths, extractGlobsFromExcludeFilesGlobMap(exclude));
fnFileExclusionTest = generateExclusionFunctionForUri(globs, workspaceRoot || '');
Object.assign(activeSettings, mergedSettings);
activeSettingsNeedUpdating = false;
triggerValidateAll.next(undefined);
}
function getActiveSettings() {
if (activeSettingsNeedUpdating) {
updateActiveSettings();
}
return activeSettings;
}
function registerConfigurationFile(path: string) {
configsToImport.add(path);
log(`Load: ${path}`);
triggerUpdateConfig.next(undefined);
}
interface TextDocumentInfo {
uri?: string;
languageId?: string;
}
// Listen for event messages from the client.
connection.onNotification('applySettings', onConfigChange);
connection.onNotification('registerConfigurationFile', registerConfigurationFile);
connection.onRequest('isSpellCheckEnabled', (params: TextDocumentInfo) => {
const { uri, languageId } = params;
return {
languageEnabled: languageId ? isLanguageEnabled(languageId) : undefined,
fileEnabled: uri ? !isUriExcluded(uri) : undefined,
};
});
connection.onRequest('getConfigurationForDocument', (params: TextDocumentInfo) => {
const { uri, languageId } = params;
const doc = uri && documents.get(uri);
const docSettings = doc && getSettingsToUseForDocument(doc);
const settings = activeSettings;
//.........这里部分代码省略.........
示例5: utf16to8
connection.window.showWarningMessage("\
The current parser options have source maps disabled.\
Without those, it's not possible to generate document symbol.\
");
return Promise.resolve([]); // I cannot let you navigate if I have no source map.
}
const textDocument = utf16to8(documents.get(symbolParam.textDocument.uri).getText());
const documentLines = textDocument.split(/\r?\n/g);
const refractOutput = refractDocuments.get(symbolParam.textDocument.uri.toString());
const symbolArray = refractUtils.extractSymbols(refractOutput, textDocument, documentLines);
return Promise.resolve(symbolArray);
} catch(err) {
connection.window.showErrorMessage(err.message);
}
});
connection.onRequest({method: "parserOutput"}, (code) => {
try {
return parser.parse(code);
} catch(e) {
return e.result;
}
})
connection.listen();
示例6: pushAll
let document = documents.get(documentSymbolParms.textDocument.uri);
let symbols: SymbolInformation[] = [];
languageModes.getAllModesInDocument(document).forEach(m => {
if (m.findDocumentSymbols) {
pushAll(symbols, m.findDocumentSymbols(document));
}
});
return symbols;
});
connection.onRequest(ColorSymbolRequest.type, uri => {
let ranges: Range[] = [];
let document = documents.get(uri);
if (document) {
languageModes.getAllModesInDocument(document).forEach(m => {
if (m.findColorSymbols) {
pushAll(ranges, m.findColorSymbols(document));
}
});
}
return ranges;
});
connection.onRequest(TagCloseRequest.type, params => {
let document = documents.get(params.textDocument.uri);
if (document) {
let mode = languageModes.getModeAtPosition(document, params.position);
if (mode && mode.doAutoClose) {
return mode.doAutoClose(document, params.position);
}
}
return null;
示例7: constructor
constructor(input: any, output: any, strict: boolean) {
this.connection = createConnection(input, output);
input.removeAllListeners('end');
input.removeAllListeners('close');
output.removeAllListeners('end');
output.removeAllListeners('close');
let workspaceRoot: string;
let documents: TextDocuments = new TextDocuments();
let closed = false;
function close() {
if (!closed) {
input.close();
output.close();
closed = true;
}
}
let service: TypeScriptService;
let self = this;
let initialized: Thenable<void> = null;
this.connection.onRequest(InitializeRequest.type, (params: InitializeParams): Promise<InitializeResult> => {
console.error('initialize', params.rootPath);
return new Promise<InitializeResult>(function (resolve) {
if (params.rootPath) {
workspaceRoot = util.uri2path(params.rootPath);
service = new TypeScriptService(workspaceRoot, strict, self.connection);
initialized = service.host.initialize(workspaceRoot);
resolve({
capabilities: {
// Tell the client that the server works in FULL text document sync mode
textDocumentSync: documents.syncKind,
hoverProvider: true,
definitionProvider: true,
referencesProvider: true
}
})
}
});
});
this.connection.onNotification(ExitRequest.type, function () {
close();
});
this.connection.onRequest(ShutdownRequest.type, function () {
return [];
});
this.connection.onDidOpenTextDocument((params: DidOpenTextDocumentParams) => {
let relpath = util.uri2relpath(params.textDocument.uri, workspaceRoot);
console.error('add file', workspaceRoot, '/', relpath);
service.addFile(relpath, params.textDocument.text);
});
this.connection.onDidCloseTextDocument((params: DidCloseTextDocumentParams) => {
let relpath = util.uri2relpath(params.textDocument.uri, workspaceRoot);
console.error('remove file', workspaceRoot, '/', relpath);
service.removeFile(relpath);
});
this.connection.onRequest(WorkspaceSymbolsRequest.type, (params: WorkspaceSymbolParamsWithLimit): Promise<SymbolInformation[]> => {
const enter = new Date().getTime();
return new Promise<SymbolInformation[]>(function (resolve, reject) {
initialized.then(function () {
let result = [];
const init = new Date().getTime();
try {
if (params.query == "exported") {
const exported = service.getExportedEnts();
if (exported) {
result = exported.map(ent => {
return SymbolInformation.create(ent.name, ent.kind, ent.location.range,
'file:///' + ent.location.file, util.formExternalUri(ent));
});
}
} else if (params.query == "externals") {
const externals = service.getExternalRefs();
if (externals) {
result = externals.map(external => {
return SymbolInformation.create(external.name, util.formEmptyKind(), util.formEmptyRange(), util.formExternalUri(external));
});
}
} else if (params.query == '') {
const topDecls = service.getTopLevelDeclarations(params.limit);
if (topDecls) {
result = topDecls.map(decl => {
return SymbolInformation.create(decl.name, decl.kind, decl.location.range,
'file:///' + decl.location.file, util.formExternalUri(decl));
});
}
} else {
//.........这里部分代码省略.........
示例8: async
connection.onRequest(
GutterPreviewImageRequestType,
async (request: ImageInfoRequest, cancellationToken: CancellationToken): Promise<ImageInfoResponse> => {
try {
let document = documents.get(request.uri);
if (document) {
const cancellation = new Promise<ImageInfo[]>((res, rej) => {
cancellationToken.onCancellationRequested(() => {
res([]);
});
});
return Promise.race([collectEntries(document, request, cancellationToken), cancellation])
.then(values => values.filter(p => !!p))
.then(entries => {
return {
images: entries.filter(p => !!p)
};
})
.catch(e => {
console.error(e);
return {
images: []
};
});
} else {
return {
images: []
};
}
} catch (e) {
console.error(e);
return {
images: []
};
}
}
);