本文整理汇总了TypeScript中vscode-languageserver.TextDocuments类的典型用法代码示例。如果您正苦于以下问题:TypeScript TextDocuments类的具体用法?TypeScript TextDocuments怎么用?TypeScript TextDocuments使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TextDocuments类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: createDiagnostics
function createDiagnostics(files: { [filePath: string]: string }, path: string) {
const docs: { [path: string]: TextDocument } = {};
Object.keys(files).reduce((prev, path: string) => {
prev[path] = TextDocument.create('/' + path, 'css', 0, files[path]);
return prev;
}, docs);
const documents: TextDocuments = {
get: filePath => {
return docs[filePath];
},
keys: () => {
return Object.keys(docs);
}
} as TextDocuments;
// const fs = new LocalSyncFs('');
const fs = new MemoryFileSystem('/', { content: files });
const docsFs = createDocFs(fs, documents);
const doc = documents.get(path);
return doc
? createDiagnosis(
doc,
Stylable.create({
fileSystem: createFs(docsFs),
projectRoot: '/'
}).fileProcessor,
require
)
: null;
}
示例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:
connection.onRequest(ColorPresentationRequest.type, params => {
const document = documents.get(params.textDocument.uri);
if (document) {
return vls.getColorPresentations(document, params.color, params.range);
}
return [];
});
示例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.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
}
};
});
示例6: if
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;
}
}
});
示例7: async
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: []
};
}
}