本文整理汇总了TypeScript中vscode-languageserver.TextDocuments.onDidClose方法的典型用法代码示例。如果您正苦于以下问题:TypeScript TextDocuments.onDidClose方法的具体用法?TypeScript TextDocuments.onDidClose怎么用?TypeScript TextDocuments.onDidClose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vscode-languageserver.TextDocuments
的用法示例。
在下文中一共展示了TextDocuments.onDidClose方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getLanguageModes
connection.onInitialize((params: InitializeParams): InitializeResult => {
let initializationOptions = params.initializationOptions;
workspacePath = params.rootPath;
languageModes = getLanguageModes(initializationOptions ? initializationOptions.embeddedLanguages : { css: true, javascript: true });
documents.onDidClose(e => {
languageModes.getAllModes().forEach(m => m.onDocumentRemoved(e.document));
});
connection.onShutdown(() => {
languageModes.getAllModes().forEach(m => m.dispose());
});
return {
capabilities: {
// Tell the client that the server works in FULL text document sync mode
textDocumentSync: documents.syncKind,
completionProvider: { resolveProvider: true, triggerCharacters: ['.', ':', '<', '"', '=', '/'] },
hoverProvider: true,
documentHighlightProvider: true,
documentRangeFormattingProvider: initializationOptions && initializationOptions['format.enable'],
documentLinkProvider: true,
definitionProvider: true,
signatureHelpProvider: { triggerCharacters: ['('] },
referencesProvider: true
}
};
});
示例2: constructor
constructor() {
this.documents = new TextDocuments();
this.subject = new Subject<DocumentEvent>();
this.documents.onDidOpen(this.emitDocumentEvent(DocumentEventKind.OPEN));
this.documents.onDidChangeContent(this.emitDocumentEvent(DocumentEventKind.CHANGE_CONTENT));
this.documents.onDidClose(this.emitDocumentEvent(DocumentEventKind.CLOSE));
}
示例3: constructor
constructor(
connection: IConnection, documents: TextDocuments, baseDir: string,
converter: AnalyzerLSPConverter, logger: Logger) {
super();
const fileLoader = new FsUrlLoader(baseDir);
const inMemoryOverlayLoader = new InMemoryOverlayUrlLoader(fileLoader);
this.inMemoryDocuments = inMemoryOverlayLoader.urlContentsMap;
this.urlLoader = inMemoryOverlayLoader;
const {fire, stream} = EventStream.create<FileEvent[]>();
this.fileChanges = stream;
documents.onDidOpen((change) => {
logger.log(`Opened: ${change.document.uri}`);
});
this.disposables.push(documents.onDidChangeContent((change) => {
logger.log(`Changed in memory: ${change.document.uri}`);
// A document has changed in memory!
const url = converter.getAnalyzerUrl(change.document);
if (!url) {
return; // don't care
}
this.inMemoryDocuments.set(url, change.document.getText());
// Publish document change so other parts of the system can react.
fire([{type: FileChangeType.Changed, uri: change.document.uri}]);
}));
this.disposables.push(documents.onDidClose((event) => {
logger.log(`Closed: ${event.document.uri}`);
// The file is no longer managed in memory, so we should delete it from
// the in-memory map.
const url = converter.getAnalyzerUrl(event.document);
if (url === undefined) {
return; // don't care
}
this.inMemoryDocuments.delete(url);
fire([{type: FileChangeType.Changed, uri: event.document.uri}]);
}));
connection.onDidChangeWatchedFiles((req) => {
for (const change of req.changes) {
logger.log(`Changed on disk: ${change.uri}`);
}
const inMemoryURIs = new Set(documents.keys());
// We will get documents.onDidChangeContent events for changes of
// in-memory buffers, so we filter them out to avoid sending duplicate
// events for those changes.
const diskBackedChanges =
req.changes.filter((ch) => !inMemoryURIs.has(ch.uri));
fire(diskBackedChanges);
});
}
示例4: catch
connection.onInitialize((params: InitializeParams): InitializeResult => {
console.log('paperclip language server initialized');
const initializationOptions = params.initializationOptions;
workspacePath = params.rootPath;
vls.initialize(workspacePath, initializationOptions.devToolsPort);
documents.onDidClose(e => {
vls.removeDocument(e.document);
});
connection.onShutdown(() => {
vls.dispose();
});
try {
fsa.emptyDirSync(TMP_DIRECTORY);
} catch(e) {
}
try {
fsa.mkdirpSync(TMP_DIRECTORY);
} catch(e) {
}
const capabilities = {
// Tell the client that the server works in FULL text document sync mode
textDocumentSync: documents.syncKind,
completionProvider: { resolveProvider: true, triggerCharacters: ['.', ':', '<', '"', '/', '@', '*'] },
signatureHelpProvider: { triggerCharacters: ['('] },
documentFormattingProvider: true,
hoverProvider: true,
documentHighlightProvider: true,
documentSymbolProvider: true,
definitionProvider: true,
referencesProvider: true,
colorProvider: true
};
return { capabilities };
});
示例5: getLanguageModes
connection.onInitialize((params: InitializeParams): InitializeResult => {
let initializationOptions = params.initializationOptions;
workspacePath = params.rootPath;
languageModes = getLanguageModes(initializationOptions ? initializationOptions.embeddedLanguages : { css: true, javascript: true });
documents.onDidClose(e => {
languageModes.onDocumentRemoved(e.document);
});
connection.onShutdown(() => {
languageModes.dispose();
});
function hasClientCapability(...keys: string[]) {
let c = params.capabilities;
for (let i = 0; c && i < keys.length; i++) {
c = c[keys[i]];
}
return !!c;
}
clientSnippetSupport = hasClientCapability('textDocument', 'completion', 'completionItem', 'snippetSupport');
clientDynamicRegisterSupport = hasClientCapability('workspace', 'symbol', 'dynamicRegistration');
scopedSettingsSupport = hasClientCapability('workspace', 'configuration');
let capabilities: ServerCapabilities & CPServerCapabilities = {
// Tell the client that the server works in FULL text document sync mode
textDocumentSync: documents.syncKind,
completionProvider: clientSnippetSupport ? { resolveProvider: true, triggerCharacters: ['.', ':', '<', '"', '=', '/', '>'] } : null,
hoverProvider: true,
documentHighlightProvider: true,
documentRangeFormattingProvider: false,
documentLinkProvider: { resolveProvider: false },
documentSymbolProvider: true,
definitionProvider: true,
signatureHelpProvider: { triggerCharacters: ['('] },
referencesProvider: true,
colorProvider: true
};
return { capabilities };
});
示例6: getDocumentSettings
// Make the text document manager listen on the connection
// for open, change and close text document events
documents.listen(connection);
let workspacePath: string;
var languageModes: LanguageModes;
let clientSnippetSupport = false;
let clientDynamicRegisterSupport = false;
let scopedSettingsSupport = false;
var globalSettings: Settings = {};
let documentSettings: { [key: string]: Thenable<Settings> } = {};
// remove document settings on close
documents.onDidClose(e => {
delete documentSettings[e.document.uri];
});
function getDocumentSettings(textDocument: TextDocument, needsDocumentSettings: () => boolean): Thenable<Settings> {
console.log('scopedSettingsSupport ' + scopedSettingsSupport + 'needsSettings ' + needsDocumentSettings());
if (scopedSettingsSupport && needsDocumentSettings()) {
let promise = documentSettings[textDocument.uri];
if (!promise) {
let scopeUri = textDocument.uri;
let configRequestParam: GetConfigurationParams = { items: [{ scopeUri, section: 'css' }, { scopeUri, section: 'html' }, { scopeUri, section: 'javascript' }] };
promise = connection.sendRequest(GetConfigurationRequest.type, configRequestParam).then(s => ({ css: s[0], html: s[1], javascript: s[2] }));
documentSettings[textDocument.uri] = promise;
}
return promise;
}
return Promise.resolve(void 0);
示例7: trace
documents.onDidSave(async (event) => {
trace(`onDidSave: ${event.document.uri}`);
const settings = await settingsCache.get(event.document.uri);
if (settings && settings.run === "onSave") {
await validateTextDocument(event.document);
}
});
// A text document was closed.
documents.onDidClose((event) => {
trace(`onDidClose: ${event.document.uri}`);
connection.sendDiagnostics({uri: event.document.uri, diagnostics: []});
document2Library.delete(event.document.uri);
// tslint:disable-next-line:no-dynamic-delete -- TODO: Refactor to use a map.
delete configPathCache[URI.parse(event.document.uri).fsPath];
});
async function loadLibrary(docUri: string) {
trace(`loadLibrary for: ${docUri}`);
const uri = URI.parse(docUri);
let promise: Thenable<string>;
const settings = await settingsCache.get(docUri);
const getGlobalPath = () => getGlobalPackageManagerPath(settings.packageManager);
if (uri.scheme === "file") {
示例8: triggerValidation
});
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 => {
cleanPendingValidation(event.document);
connection.sendDiagnostics({ uri: event.document.uri, diagnostics: [] });
});
function cleanPendingValidation(textDocument: TextDocument): void {
let request = pendingValidationRequests[textDocument.uri];
if (request) {
clearTimeout(request);
delete pendingValidationRequests[textDocument.uri];
}
}
function triggerValidation(textDocument: TextDocument): void {
cleanPendingValidation(textDocument);
pendingValidationRequests[textDocument.uri] = setTimeout(() => {
delete pendingValidationRequests[textDocument.uri];
validateTextDocument(textDocument);
示例9: debouncedValidateTextDocument
documentSymbolProvider: true,
textDocumentSync: documents.syncKind,
};
return {
capabilities,
} as InitializeResult;
});
documents.onDidChangeContent((change) => {
debouncedValidateTextDocument(change.document);
});
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));
示例10: run
//.........这里部分代码省略.........
}
lastDurationSelector = new Rx.Subject<number>();
Rx.Observable.timer(activeSettings.spellCheckDelayMs || defaultDebounce).subscribe(lastDurationSelector);
return lastDurationSelector;
})
.do(doc => log(`Validate: ${doc.uri}`))
.do(() => lastDurationSelector = undefined)
.subscribe(validateTextDocument);
// Clear the diagnostics for documents we do not want to validate
const disposableSkipValidationStream = validationRequestStream
.filter(doc => !shouldValidateDocument(doc))
.do(doc => log(`Skip Validate: ${doc.uri}`))
.subscribe(doc => {
connection.sendDiagnostics({ uri: doc.uri, diagnostics: [] });
});
const disposableTriggerUpdateConfigStream = triggerUpdateConfig
.do(() => log('Trigger Update Config'))
.do(() => activeSettingsNeedUpdating = true)
.debounceTime(100)
.subscribe(() => {
updateActiveSettings();
});
const disposableTriggerValidateAll = triggerValidateAll
.debounceTime(250)
.subscribe(() => {
log('Validate all documents');
documents.all().forEach(doc => validationRequestStream.next(doc));
});
validationFinishedStream.next({ uri: 'start', version: 0 });
function shouldValidateDocument(textDocument: TextDocument): boolean {
const { uri, languageId } = textDocument;
return !!getActiveSettings().enabled && isLanguageEnabled(languageId)
&& !isUriExcluded(uri);
}
function isLanguageEnabled(languageId: string) {
const { enabledLanguageIds = []} = getActiveSettings();
return enabledLanguageIds.indexOf(languageId) >= 0;
}
function isUriExcluded(uri: string) {
return fnFileExclusionTest(uri);
}
function getBaseSettings() {
return {...CSpell.mergeSettings(defaultSettings, getActiveSettings()), enabledLanguageIds: getActiveSettings().enabledLanguageIds};
}
function getSettingsToUseForDocument(doc: TextDocument) {
return tds.constructSettingsForText(getBaseSettings(), doc.getText(), doc.languageId);
}
function validateTextDocument(textDocument: TextDocument): void {
try {
const settingsToUse = getSettingsToUseForDocument(textDocument);
if (settingsToUse.enabled) {
Validator.validateTextDocument(textDocument, settingsToUse).then(diagnostics => {
// Send the computed diagnostics to VSCode.
validationFinishedStream.next(textDocument);
connection.sendDiagnostics({ uri: textDocument.uri, diagnostics });
});
}
} catch (e) {
console.log(e);
}
}
// Make the text document manager listen on the connection
// for open, change and close text document events
documents.listen(connection);
// 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) => {
validationRequestStream.next(change.document);
});
documents.onDidClose((event) => {
// A text document was closed we clear the diagnostics
connection.sendDiagnostics({ uri: event.document.uri, diagnostics: [] });
});
connection.onCodeAction(onCodeActionHandler(documents, getBaseSettings));
// Listen on the connection
connection.listen();
// Free up the validation streams on shutdown.
connection.onShutdown(() => {
disposableSkipValidationStream.unsubscribe();
disposeValidationStream.unsubscribe();
disposableTriggerUpdateConfigStream.unsubscribe();
disposableTriggerValidateAll.unsubscribe();
});
}