本文整理汇总了C#中ITextBuffer.AsTextContainer方法的典型用法代码示例。如果您正苦于以下问题:C# ITextBuffer.AsTextContainer方法的具体用法?C# ITextBuffer.AsTextContainer怎么用?C# ITextBuffer.AsTextContainer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITextBuffer
的用法示例。
在下文中一共展示了ITextBuffer.AsTextContainer方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TagComputer
public TagComputer(
ITextBuffer subjectBuffer,
IForegroundNotificationService notificationService,
IAsynchronousOperationListener asyncListener,
ClassificationTypeMap typeMap,
SyntacticClassificationTaggerProvider taggerProvider)
{
_subjectBuffer = subjectBuffer;
_notificationService = notificationService;
_listener = asyncListener;
_typeMap = typeMap;
_taggerProvider = taggerProvider;
_workQueue = new AsynchronousSerialWorkQueue(asyncListener);
_reportChangeCancellationSource = new CancellationTokenSource();
_lastLineCache = new LastLineCache();
_workspaceRegistration = Workspace.GetWorkspaceRegistration(subjectBuffer.AsTextContainer());
_workspaceRegistration.WorkspaceChanged += OnWorkspaceRegistrationChanged;
if (_workspaceRegistration.Workspace != null)
{
ConnectToWorkspace(_workspaceRegistration.Workspace);
}
}
示例2: NavigationBarController
public NavigationBarController(
INavigationBarPresenter presenter,
ITextBuffer subjectBuffer,
IWaitIndicator waitIndicator,
IAsynchronousOperationListener asyncListener)
{
_presenter = presenter;
_subjectBuffer = subjectBuffer;
_waitIndicator = waitIndicator;
_asyncListener = asyncListener;
_workspaceRegistration = Workspace.GetWorkspaceRegistration(subjectBuffer.AsTextContainer());
_workspaceRegistration.WorkspaceChanged += OnWorkspaceRegistrationChanged;
presenter.CaretMoved += OnCaretMoved;
presenter.ViewFocused += OnViewFocused;
presenter.DropDownFocused += OnDropDownFocused;
presenter.ItemSelected += OnItemSelected;
subjectBuffer.PostChanged += OnSubjectBufferPostChanged;
// Initialize the tasks to be an empty model so we never have to deal with a null case.
_modelTask = Task.FromResult(
new NavigationBarModel(
SpecializedCollections.EmptyList<NavigationBarItem>(),
default(VersionStamp),
null));
_selectedItemInfoTask = Task.FromResult(new NavigationBarSelectedTypeAndMember(null, null));
if (_workspaceRegistration.Workspace != null)
{
ConnectToWorkspace(_workspaceRegistration.Workspace);
}
}
示例3: TryGetTextUndoHistory
public bool TryGetTextUndoHistory(Workspace editorWorkspace, ITextBuffer textBuffer, out ITextUndoHistory undoHistory)
{
undoHistory = null;
if (!(editorWorkspace is VisualStudioWorkspaceImpl) &&
!(editorWorkspace is MiscellaneousFilesWorkspace))
{
return false;
}
// TODO: Handle undo if context changes
var documentId = editorWorkspace.GetDocumentIdInCurrentContext(textBuffer.AsTextContainer());
if (documentId == null)
{
return false;
}
var document = GetDocument(editorWorkspace, documentId);
if (document == null)
{
return false;
}
undoHistory = document.GetTextUndoHistory();
return true;
}
示例4: CreateDocument
///<summary>Creates a new document linked to an existing text buffer.</summary>
public DocumentId CreateDocument(ProjectId projectId, ITextBuffer buffer, string debugName = null)
{
var id = DocumentId.CreateNewId(projectId, debugName);
TryApplyChanges(CurrentSolution.AddDocument(id, debugName ?? "Sample Document", TextLoader.From(buffer.AsTextContainer(), VersionStamp.Create())));
OpenDocument(id, buffer);
return id;
}
示例5: CreateDocument
///<summary>Creates a new document linked to an existing text buffer.</summary>
public DocumentId CreateDocument(ProjectId projectId, ITextBuffer buffer)
{
// Our GetFileName() extension (which should probably be deleted) doesn't work on projection buffers
var debugName = TextBufferExtensions.GetFileName(buffer) ?? "Markdown Embedded Code";
var id = DocumentId.CreateNewId(projectId, debugName);
TryApplyChanges(CurrentSolution.AddDocument(
id, debugName,
TextLoader.From(buffer.AsTextContainer(), VersionStamp.Create())
));
OpenDocument(id, buffer);
return id;
}
示例6: CreateDocument
///<summary>Creates a new document linked to an existing text buffer.</summary>
public Document CreateDocument(ProjectId projectId, ITextBuffer buffer)
{
var id = DocumentId.CreateNewId(projectId);
documentBuffers.Add(id, buffer);
// Our GetFileName() extension (which should probably be deleted) doesn't work on projection buffers
var docInfo = DocumentInfo.Create(id, TextBufferExtensions.GetFileName(buffer) ?? "Markdown Embedded Code",
loader: TextLoader.From(buffer.AsTextContainer(), VersionStamp.Create()),
sourceCodeKind: SourceCodeKind.Script
);
OnDocumentAdded(docInfo);
OnDocumentOpened(id, buffer.AsTextContainer());
buffer.Changed += delegate { OnDocumentContextUpdated(id); };
return CurrentSolution.GetDocument(id);
}
示例7: SetSubmissionDocument
private void SetSubmissionDocument(ITextBuffer buffer, Project project)
{
var documentId = DocumentId.CreateNewId(project.Id, debugName: project.Name);
var solution = project.Solution
.AddDocument(documentId, project.Name, buffer.CurrentSnapshot.AsText());
_workspace.SetCurrentSolution(solution);
// opening document will start workspace listening to changes in this text container
_workspace.OpenDocument(documentId, buffer.AsTextContainer());
}
示例8: Source
public Source(SuggestedActionsSourceProvider owner, ITextView textView, ITextBuffer textBuffer)
{
_owner = owner;
_textView = textView;
_textView.Closed += OnTextViewClosed;
_subjectBuffer = textBuffer;
_registration = Workspace.GetWorkspaceRegistration(textBuffer.AsTextContainer());
_lastSolutionVersionReported = InvalidSolutionVersion;
var updateSource = (IDiagnosticUpdateSource)_owner._diagnosticService;
updateSource.DiagnosticsUpdated += OnDiagnosticsUpdated;
if (_registration.Workspace != null)
{
_workspace = _registration.Workspace;
_workspace.DocumentActiveContextChanged += OnActiveContextChanged;
}
_registration.WorkspaceChanged += OnWorkspaceChanged;
}
示例9: TagComputer
public TagComputer(
ITextBuffer subjectBuffer,
IForegroundNotificationService notificationService,
IAsynchronousOperationListener asyncListener,
ClassificationTypeMap typeMap,
SyntacticClassificationTaggerProvider taggerProvider,
IViewSupportsClassificationService viewSupportsClassificationServiceOpt,
ITextBufferAssociatedViewService associatedViewService,
IEditorClassificationService editorClassificationService,
string languageName)
{
_subjectBuffer = subjectBuffer;
_notificationService = notificationService;
_listener = asyncListener;
_typeMap = typeMap;
_taggerProvider = taggerProvider;
_viewSupportsClassificationServiceOpt = viewSupportsClassificationServiceOpt;
_associatedViewService = associatedViewService;
_editorClassificationService = editorClassificationService;
_languageName = languageName;
_workQueue = new AsynchronousSerialWorkQueue(asyncListener);
_reportChangeCancellationSource = new CancellationTokenSource();
_lastLineCache = new LastLineCache();
_workspaceRegistration = Workspace.GetWorkspaceRegistration(subjectBuffer.AsTextContainer());
_workspaceRegistration.WorkspaceChanged += OnWorkspaceRegistrationChanged;
ConnectToWorkspace(_workspaceRegistration.Workspace);
}
示例10: OpenDocument
///<summary>Links an existing <see cref="Document"/> to an <see cref="ITextBuffer"/>, synchronizing their contents.</summary>
public void OpenDocument(DocumentId documentId, ITextBuffer buffer)
{
documentBuffers.Add(documentId, buffer);
OnDocumentOpened(documentId, buffer.AsTextContainer());
buffer.Changed += delegate { OnDocumentContextUpdated(documentId); };
}
示例11: SetSubmissionDocument
private void SetSubmissionDocument(ITextBuffer buffer, Project project)
{
// Try to unregister our buffer with our workspace. This is a bit of a hack,
// but we may have registered the buffer with the workspace if it was
// transitioned to an Interactive Command buffer.
_workspace.UnregisterText(buffer.AsTextContainer());
var documentId = DocumentId.CreateNewId(project.Id, debugName: project.Name);
var solution = project.Solution
.AddDocument(documentId, project.Name, buffer.CurrentSnapshot.AsText());
_workspace.SetCurrentSolution(solution);
// opening document will start workspace listening to changes in this text container
_workspace.OpenDocument(documentId, buffer.AsTextContainer());
}
示例12: AbstractWorkspaceTrackingTaggerEventSource
protected AbstractWorkspaceTrackingTaggerEventSource(ITextBuffer subjectBuffer, TaggerDelay delay) : base(delay)
{
this.SubjectBuffer = subjectBuffer;
_workspaceRegistration = Workspace.GetWorkspaceRegistration(subjectBuffer.AsTextContainer());
}
示例13: InitializeAsync
async Task InitializeAsync(ITextBuffer buffer, string code, MetadataReference[] refs, string languageName, ISynchronousTagger<IClassificationTag> tagger, CompilationOptions compilationOptions, ParseOptions parseOptions) {
using (var workspace = new AdhocWorkspace(RoslynMefHostServices.DefaultServices)) {
var documents = new List<DocumentInfo>();
var projectId = ProjectId.CreateNewId();
documents.Add(DocumentInfo.Create(DocumentId.CreateNewId(projectId), "main.cs", null, SourceCodeKind.Regular, TextLoader.From(buffer.AsTextContainer(), VersionStamp.Create())));
var projectInfo = ProjectInfo.Create(projectId, VersionStamp.Create(), "compilecodeproj", Guid.NewGuid().ToString(), languageName,
compilationOptions: compilationOptions
.WithOptimizationLevel(OptimizationLevel.Release)
.WithPlatform(Platform.AnyCpu)
.WithAssemblyIdentityComparer(DesktopAssemblyIdentityComparer.Default),
parseOptions: parseOptions,
documents: documents,
metadataReferences: refs,
isSubmission: false, hostObjectType: null);
workspace.AddProject(projectInfo);
foreach (var doc in documents)
workspace.OpenDocument(doc.Id);
buffer.Replace(new Span(0, buffer.CurrentSnapshot.Length), code);
{
// Initialize classification code paths
var spans = new NormalizedSnapshotSpanCollection(new SnapshotSpan(buffer.CurrentSnapshot, 0, buffer.CurrentSnapshot.Length));
foreach (var tagSpan in tagger.GetTags(spans, CancellationToken.None)) { }
}
{
// Initialize completion code paths
var info = CompletionInfo.Create(buffer.CurrentSnapshot);
Debug.Assert(info != null);
if (info != null) {
var completionTrigger = CompletionTrigger.Default;
var completionList = await info.Value.CompletionService.GetCompletionsAsync(info.Value.Document, 0, completionTrigger);
}
}
{
// Initialize signature help code paths
var info = SignatureHelpInfo.Create(buffer.CurrentSnapshot);
Debug.Assert(info != null);
if (info != null) {
int sigHelpIndex = code.IndexOf("sighelp");
Debug.Assert(sigHelpIndex >= 0);
var triggerInfo = new SignatureHelpTriggerInfo(SignatureHelpTriggerReason.InvokeSignatureHelpCommand);
var items = await info.Value.SignatureHelpService.GetItemsAsync(info.Value.Document, sigHelpIndex, triggerInfo);
}
}
{
// Initialize quick info code paths
var info = QuickInfoState.Create(buffer.CurrentSnapshot);
Debug.Assert(info != null);
if (info != null) {
int quickInfoIndex = code.IndexOf("Equals");
Debug.Assert(quickInfoIndex >= 0);
var item = await info.Value.QuickInfoService.GetItemAsync(info.Value.Document, quickInfoIndex);
}
}
}
}