public abstract GetOrCreate ( ITextBuffer textBuffer ) : Uri | ||
textBuffer | ITextBuffer | |
리턴 | Uri |
public override void TrackDocument(ITextBuffer buffer) { if (buffer is null) { throw new ArgumentNullException(nameof(buffer)); } Debug.Assert(_joinableTaskContext.IsOnMainThread); var uri = _fileUriProvider.GetOrCreate(buffer); if (_documents.TryGetValue(uri, out _)) { throw new InvalidOperationException($"Can not track document that's already being tracked {uri}"); } var lspDocument = _documentFactory.Create(buffer); _documents[uri] = lspDocument; NotifyDocumentManagerChangeListeners( old: null, @new: lspDocument.CurrentSnapshot, virtualOld: null, virtualNew: null, LSPDocumentChangeKind.Added); }
public override LSPDocument Create(ITextBuffer buffer) { if (buffer is null) { throw new ArgumentNullException(nameof(buffer)); } var uri = _fileUriProvider.GetOrCreate(buffer); var virtualDocuments = CreateVirtualDocuments(buffer); var lspDocument = new DefaultLSPDocument(uri, buffer, virtualDocuments); return(lspDocument); }
public override void TrackDocument(ITextBuffer buffer) { if (buffer is null) { throw new ArgumentNullException(nameof(buffer)); } Debug.Assert(_joinableTaskContext.IsOnMainThread); var uri = _fileUriProvider.GetOrCreate(buffer); if (_documents.TryGetValue(uri, out _)) { throw new InvalidOperationException($"Can not track document that's already being tracked {uri}"); } var lspDocument = _documentFactory.Create(buffer); _documents[uri] = lspDocument; var args = new LSPDocumentChangeEventArgs(old: null, lspDocument.CurrentSnapshot, LSPDocumentChangeKind.Added); Changed?.Invoke(this, args); }
public override bool TryCreateFor(ITextBuffer hostDocumentBuffer, out VirtualDocument virtualDocument) { if (hostDocumentBuffer is null) { throw new ArgumentNullException(nameof(hostDocumentBuffer)); } if (!hostDocumentBuffer.ContentType.IsOfType(HostDocumentContentTypeName)) { // Another content type we don't care about. virtualDocument = null; return(false); } var hostDocumentUri = _fileUriProvider.GetOrCreate(hostDocumentBuffer); // E.g. Index.cshtml => Index.cshtml__virtual.html (for html), similar for other languages var virtualLanguageFilePath = hostDocumentUri.GetAbsoluteOrUNCPath() + LanguageFileNameSuffix; var virtualLanguageUri = new Uri(virtualLanguageFilePath); var languageBuffer = _textBufferFactory.CreateTextBuffer(); _fileUriProvider.AddOrUpdate(languageBuffer, virtualLanguageUri); // This ensures that LiveShare does not serialize this virtual document to disk in LiveShare & Codespaces scenarios. languageBuffer.Properties.AddProperty(ContainedLanguageMarker, true); if (!(LanguageBufferProperties is null)) { foreach (var keyValuePair in LanguageBufferProperties) { languageBuffer.Properties.AddProperty(keyValuePair.Key, keyValuePair.Value); } } // Create a text document to trigger language server initialization for the contained language. _textDocumentFactory.CreateTextDocument(languageBuffer, virtualLanguageFilePath); languageBuffer.ChangeContentType(LanguageContentType, editTag: null); virtualDocument = CreateVirtualDocument(virtualLanguageUri, languageBuffer); return(true); }