本文整理汇总了TypeScript中vscode-languageserver.IConnection.onDidChangeConfiguration方法的典型用法代码示例。如果您正苦于以下问题:TypeScript IConnection.onDidChangeConfiguration方法的具体用法?TypeScript IConnection.onDidChangeConfiguration怎么用?TypeScript IConnection.onDidChangeConfiguration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vscode-languageserver.IConnection
的用法示例。
在下文中一共展示了IConnection.onDidChangeConfiguration方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: if
let formatterRegistration: Thenable<Disposable> = null;
// The settings have changed. Is send on server activation as well.
connection.onDidChangeConfiguration((change) => {
globalSettings = change.settings;
documentSettings = {}; // reset all document settings
languageModes.getAllModes().forEach(m => {
if (m.configure) {
m.configure(change.settings);
}
});
documents.all().forEach(triggerValidation);
// dynamically enable & disable the formatter
if (clientDynamicRegisterSupport) {
let enableFormatter = globalSettings && globalSettings.html && globalSettings.html.format && globalSettings.html.format.enable;
if (enableFormatter) {
if (!formatterRegistration) {
let documentSelector: DocumentSelector = [{ language: 'html' }, { language: 'handlebars' }]; // don't register razor, the formatter does more harm than good
formatterRegistration = connection.client.register(DocumentRangeFormattingRequest.type, { documentSelector });
}
} else if (formatterRegistration) {
formatterRegistration.then(r => r.dispose());
formatterRegistration = null;
}
}
});
let pendingValidationRequests: { [uri: string]: NodeJS.Timer } = {};
const validationDelayMs = 200;
示例2: validateTextDocument
});
documents.onDidClose((event) => {
connection.sendDiagnostics({ diagnostics: [], uri: event.document.uri });
});
let currentSettings: ApiElementsSettings;
let desideredSymbols = defaultRefractSymbolsTree;
connection.onDidChangeConfiguration((change) => {
const apiElementsSettings: ApiElementsSettings = change.settings.apiElements;
currentSettings = lodash.cloneDeep(apiElementsSettings);
debouncedValidateTextDocument = lodash.debounce(validateTextDocument, apiElementsSettings.validation.debounce);
const desideredSymbolNames =
Object.keys(apiElementsSettings.symbols).filter((sym) => apiElementsSettings.symbols[sym] === true);
desideredSymbols =
defaultRefractSymbolsTree.filter((sym) => lodash.includes(desideredSymbolNames, sym.friendlyName));
// Revalidate any open text documents
documents.all().forEach(validateTextDocument);
});
function validateTextDocument(textDocument: TextDocument): void {
const diagnostics: Diagnostic[] = [];
const text = textDocument.getText();
parse(text, currentSettings.parser)
.then((output) => output, (error) => error.result)
.then((refractOutput) => {
示例3:
documentHighlightProvider: true,
documentRangeFormattingProvider: initializationOptions && initializationOptions['format.enable'],
documentLinkProvider: true,
definitionProvider: true,
signatureHelpProvider: { triggerCharacters: ['('] },
referencesProvider: true
}
};
});
// The settings have changed. Is send on server activation as well.
connection.onDidChangeConfiguration((change) => {
languageModes.getAllModes().forEach(m => {
if (m.configure) {
m.configure(change.settings);
}
});
documents.all().forEach(triggerValidation);
});
let pendingValidationRequests: { [uri: string]: NodeJS.Timer } = {};
const validationDelayMs = 200;
// The content of a text document has changed. This event is emitted
// when the text document first opened or when its content has changed.
documents.onDidChangeContent(change => {
triggerValidation(change.document);
});
// a document has closed: clear all diagnostics
documents.onDidClose(event => {
示例4: validateTextDocument
interface ApiElementsSettings {
parser: ParserSettings;
};
interface ParserSettings {
exportSourcemap: boolean;
json: boolean;
requireBlueprintName: boolean;
type: string;
};
let currentSettings : ApiElementsSettings;
connection.onDidChangeConfiguration((change) => {
currentSettings = lodash.cloneDeep(change.settings.apiElements);
// Revalidate any open text documents
documents.all().forEach(validateTextDocument);
});
function validateTextDocument(textDocument: TextDocument): void {
let diagnostics: Diagnostic[] = [];
let text = textDocument.getText();
let refractOutput = undefined;
try {
refractOutput = parser.parse(text, currentSettings.parser);
} catch(err) {
refractOutput = err.result;
} finally {
示例5: 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;
//.........这里部分代码省略.........
示例6: initStylableLanguageService
//.........这里部分代码省略.........
} catch (e) {
/*Client has no workspace/configuration method, ignore silently */
}
docsDispatcher.keys!().forEach(key => {
const doc = docsDispatcher.get!(key);
if (!!doc) {
if (doc.languageId === 'stylable') {
let diagnostics: Diagnostic[];
if (
ignore &&
(res.diagnostics.ignore as string[]).some(p => {
return fromVscodePath(doc.uri).startsWith(path.resolve(p));
})
) {
diagnostics = [];
} else {
diagnostics = createDiagnosis(doc, processor, services.requireModule)
.map(diag => {
diag.source = 'stylable';
return diag;
})
.concat(newCssService.getDiagnostics(doc));
}
connection.sendDiagnostics({ uri: doc.uri, diagnostics });
}
}
});
}
// docsDispatcher.onDidOpen(diagnose);
docsDispatcher.onDidChangeContent(diagnose);
connection.onDidChangeConfiguration(diagnose);
connection.onDefinition(
async (params): Promise<Definition> => {
const doc = fs.loadTextFileSync(params.textDocument.uri);
const pos = params.position;
const res = await provider
.getDefinitionLocation(doc, {
line: pos.line,
character: pos.character
}, fromVscodePath(params.textDocument.uri), fs);
return res.map(loc => Location.create(toVscodePath(loc.uri), loc.range));
}
);
connection.onHover(
(params: TextDocumentPositionParams): Hover | null => {
return newCssService.doHover(fs.get(params.textDocument.uri), params.position);
}
);
connection.onReferences(
(params: ReferenceParams): Location[] => {
const refs = getRefs(params, fs, services.styl);
if (refs.length) {
return dedupeRefs(refs);
} else {
return dedupeRefs(newCssService.findReferences(fs.get(params.textDocument.uri), params.position));
}
}
);
示例7:
});
let validation = {
html: true,
css: true,
javascript: true
};
// The settings have changed. Is send on server activation as well.
connection.onDidChangeConfiguration((change) => {
settings = change.settings;
let validationSettings = settings && settings.html && settings.html.validate || {};
validation.css = validationSettings.styles !== false;
validation.javascript = validationSettings.scripts !== false;
languageModes.getAllModes().forEach(m => {
if (m.configure) {
m.configure(change.settings);
}
});
documents.all().forEach(triggerValidation);
});
let pendingValidationRequests: { [uri: string]: NodeJS.Timer } = {};
const validationDelayMs = 200;
// The content of a text document has changed. This event is emitted
// when the text document first opened or when its content has changed.
documents.onDidChangeContent(change => {
triggerValidation(change.document);
});
示例8: validateTextDocument
// Tell the client that the server works in FULL text document sync mode
textDocumentSync: documents.syncKind
}
}
});
// The content of a text document has changed. This event is emitted
// when the text document first opened or when its content has changed.
documents.onDidChangeContent((change) => {
validateTextDocument(change.document);
});
// The settings have changed. Is send on server activation
// as well.
connection.onDidChangeConfiguration((change) => {
// Revalidate any open text documents
documents.all().forEach(validateTextDocument);
});
let errorRegex = new RegExp('\\[([^\\]]+)\\] line (\\d+), column (\\d+): (.+)');
function validateTextDocument(textDocument: ITextDocument): void {
let linterBinPath = path.join(__dirname, '../../server/glualint');
connection.console.log("lel");
connection.console.log(linterBinPath);
let stdout = childProcess.execFileSync(linterBinPath, ['stdin'], {input: textDocument.getText()});
let diagnostics: Diagnostic[] = [];
let lines = stdout.toString().split('\n');
for (let i = 0; i < lines.length; i++) {
let m = errorRegex.exec(lines[i]);
示例9: validateTextDocument
languageServerExample: ExampleSettings;
}
// These are the example settings we defined in the client's package.json
// file
interface ExampleSettings {
maxNumberOfProblems: number;
}
// hold the maxNumberOfProblems setting
let maxNumberOfProblems: number;
// The settings have changed. Is send on server activation
// as well.
connection.onDidChangeConfiguration((change) => {
//let settings = <Settings>change.settings;
//maxNumberOfProblems = settings.languageServerExample.maxNumberOfProblems || 100;
// Revalidate any open text documents
//documents.all().forEach(validateTextDocument);
});
function validateTextDocument(textDocument: ITextDocument): void {
let diagnostics: Diagnostic[] = [];
let lines = textDocument.getText().split(/\r?\n/g);
let problems = 0;
for (var i = 0; i < lines.length && problems < maxNumberOfProblems; i++) {
let line = lines[i];
let index = line.indexOf('typescript');
if (index >= 0) {
problems++;
diagnostics.push({
severity: DiagnosticSeverity.Warning,
range: {
示例10: require
packageFile = require(`${params.rootPath}/package.json`);
} catch (err) {
// Skip error
}
if (configFiles.length !== 0 || (packageFile && packageFile.hasOwnProperty('pugLintConfig'))) {
return Promise.reject(new ResponseError<InitializeError>(99, puglintNotFound, { retry: true }));
}
});
});
});
connection.onDidChangeConfiguration((params) => {
editorSettings = params.settings.puglint;
if (!configResolver) {
return;
}
validateMany(allDocuments.all());
});
connection.onDidChangeWatchedFiles(() => {
configWatcherStatus = true;
if (!configResolver) {
return;
}
validateMany(allDocuments.all());
});
allDocuments.onDidClose((event) => {
connection.sendDiagnostics({ uri: event.document.uri, diagnostics: [] });