public LanguageSettingsPersister( [Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider, IGlobalOptionService optionService) : base(assertIsForeground: true) { _textManager = (IVsTextManager4)serviceProvider.GetService(typeof(SVsTextManager)); _optionService = optionService; // TODO: make this configurable _languageMap = BidirectionalMap <string, Tuple <Guid> > .Empty.Add(LanguageNames.CSharp, Tuple.Create(Guids.CSharpLanguageServiceId)) .Add(LanguageNames.VisualBasic, Tuple.Create(Guids.VisualBasicLanguageServiceId)) .Add("TypeScript", Tuple.Create(new Guid("4a0dddb5-7a95-4fbf-97cc-616d07737a77"))) .Add("F#", Tuple.Create(new Guid("BC6DD5A5-D4D6-4dab-A00D-A51242DBAF1B"))) .Add("Xaml", Tuple.Create(new Guid("CD53C9A1-6BC2-412B-BE36-CC715ED8DD41"))); foreach (var languageGuid in _languageMap.Values) { var languagePreferences = new LANGPREFERENCES3[1]; languagePreferences[0].guidLang = languageGuid.Item1; // The function can potentially fail if that language service isn't installed if (ErrorHandler.Succeeded(_textManager.GetUserPreferences4(pViewPrefs: null, pLangPrefs: languagePreferences, pColorPrefs: null))) { RefreshLanguageSettings(languagePreferences); } } _textManagerEvents2Sink = ComEventSink.Advise <IVsTextManagerEvents4>(_textManager, this); }
public LanguageSettingsPersister( [Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider, IGlobalOptionService optionService) : base(assertIsForeground: true) { _textManager = (IVsTextManager4)serviceProvider.GetService(typeof(SVsTextManager)); _optionService = optionService; // TODO: make this configurable _languageMap = BidirectionalMap<string, Tuple<Guid>>.Empty.Add(LanguageNames.CSharp, Tuple.Create(Guids.CSharpLanguageServiceId)) .Add(LanguageNames.VisualBasic, Tuple.Create(Guids.VisualBasicLanguageServiceId)) .Add("TypeScript", Tuple.Create(new Guid("4a0dddb5-7a95-4fbf-97cc-616d07737a77"))) .Add("F#", Tuple.Create(new Guid("BC6DD5A5-D4D6-4dab-A00D-A51242DBAF1B"))) .Add("Xaml", Tuple.Create(new Guid("CD53C9A1-6BC2-412B-BE36-CC715ED8DD41"))); foreach (var languageGuid in _languageMap.Values) { var languagePreferences = new LANGPREFERENCES3[1]; languagePreferences[0].guidLang = languageGuid.Item1; // The function can potentially fail if that language service isn't installed if (ErrorHandler.Succeeded(_textManager.GetUserPreferences4(pViewPrefs: null, pLangPrefs: languagePreferences, pColorPrefs: null))) { RefreshLanguageSettings(languagePreferences); } } _textManagerEvents2Sink = ComEventSink.Advise<IVsTextManagerEvents4>(_textManager, this); }
public LanguageSettingsPersister( [Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider, IGlobalOptionService optionService) : base(assertIsForeground: true) { _textManager = (IVsTextManager4)serviceProvider.GetService(typeof(SVsTextManager)); _optionService = optionService; // TODO: make this configurable _languageMap = BidirectionalMap <string, Tuple <Guid> > .Empty.Add(LanguageNames.Hlsl, Tuple.Create(Guids.HlslLanguageServiceId)) .Add(LanguageNames.ShaderLab, Tuple.Create(Guids.ShaderLabLanguageServiceId)); foreach (var languageGuid in _languageMap.Values) { var languagePreferences = new LANGPREFERENCES3[1]; languagePreferences[0].guidLang = languageGuid.Item1; // The function can potentially fail if that language service isn't installed if (ErrorHandler.Succeeded(_textManager.GetUserPreferences4(pViewPrefs: null, pLangPrefs: languagePreferences, pColorPrefs: null))) { RefreshLanguageSettings(languagePreferences); } } _textManagerEvents2Sink = ComEventSink.Advise <IVsTextManagerEvents4>(_textManager, this); }
private void TrackOpenedDocument(uint docCookie, string moniker) { var languageInformation = TryGetLanguageInformation(moniker); if (languageInformation == null) { // We can never put this document in a workspace, so just bail return; } // We don't want to realize the document here unless it's already initialized. Document initialization is watched in // OnAfterAttributeChangeEx and will retrigger this if it wasn't already done. if (_runningDocumentTable.IsDocumentInitialized(docCookie) && !_docCookieToWorkspaceRegistration.ContainsKey(docCookie)) { var vsTextBuffer = (IVsTextBuffer)_runningDocumentTable.GetDocumentData(docCookie); var textBuffer = _editorAdaptersFactoryService.GetDocumentBuffer(vsTextBuffer); // As long as the buffer is initialized, then we should see if we should attach if (textBuffer != null) { var registration = Workspace.GetWorkspaceRegistration(textBuffer.AsTextContainer()); registration.WorkspaceChanged += Registration_WorkspaceChanged; _docCookieToWorkspaceRegistration = _docCookieToWorkspaceRegistration.Add(docCookie, registration); if (!IsClaimedByAnotherWorkspace(registration)) { AttachToDocument(docCookie, moniker); } } } }
public void RemoveTextContainer(SourceTextContainer textContainer) { if (textContainer == null) { throw new ArgumentNullException(nameof(textContainer)); } lock (_project._gate) { if (!_sourceTextContainersToDocumentIds.TryGetValue(textContainer, out var documentId)) { throw new ArgumentException($"{nameof(textContainer)} is not a text container added to this project."); } _sourceTextContainersToDocumentIds = _sourceTextContainersToDocumentIds.RemoveKey(textContainer); // if the TextContainer had a full path provided, remove it from the map. var entry = _documentPathsToDocumentIds.Where(kv => kv.Value == documentId).FirstOrDefault(); if (entry.Key != null) { _documentPathsToDocumentIds.Remove(entry.Key); } // There are two cases: // // 1. This file is actually been pushed to the workspace, and we need to remove it (either // as a part of the active batch or immediately) // 2. It hasn't been pushed yet, but is contained in _documentsAddedInBatch if (_project._workspace.CurrentSolution.GetDocument(documentId) != null) { if (_project._activeBatchScopes > 0) { _documentsRemovedInBatch.Add(documentId); } else { _project._workspace.ApplyChangeToWorkspace(w => { w.OnDocumentClosed(documentId, new SourceTextLoader(textContainer, filePath: null)); _documentRemoveAction(w, documentId); _project._workspace.RemoveDocumentToDocumentsNotFromFiles(documentId); }); } } else { for (int i = 0; i < _documentsAddedInBatch.Count; i++) { if (_documentsAddedInBatch[i].Id == documentId) { _documentsAddedInBatch.RemoveAt(i); break; } } } } }
private void CreateSignatures( ITrackingSpan triggerSpan, int?selectedParameter) { _signatureMap = BidirectionalMap <SignatureHelpItem, Signature> .Empty; foreach (var item in _signatureHelpItems) { _signatureMap = _signatureMap.Add(item, new Signature(triggerSpan, item, GetParameterIndexForItem(item, selectedParameter))); } }
private void RemoveDocumentFromWorkspace_NoLock(MetadataAsSourceGeneratedFileInfo fileInfo) { var documentId = _openedDocumentIds.GetValueOrDefault(fileInfo); Contract.ThrowIfNull(documentId); _workspace.OnDocumentClosed(documentId, new FileTextLoader(fileInfo.TemporaryFilePath, fileInfo.Encoding)); _workspace.OnProjectRemoved(documentId.ProjectId); _openedDocumentIds = _openedDocumentIds.RemoveKey(fileInfo); }
public DocumentId AddTextContainer(SourceTextContainer textContainer, string fullPath, SourceCodeKind sourceCodeKind, ImmutableArray <string> folders) { if (textContainer == null) { throw new ArgumentNullException(nameof(textContainer)); } var documentId = DocumentId.CreateNewId(_project.Id, fullPath); var textLoader = new SourceTextLoader(textContainer, fullPath); var documentInfo = DocumentInfo.Create( documentId, FileNameUtilities.GetFileName(fullPath), folders: folders.IsDefault ? null : (IEnumerable <string>)folders, sourceCodeKind: sourceCodeKind, loader: textLoader, filePath: fullPath); lock (_project._gate) { if (_sourceTextContainersToDocumentIds.ContainsKey(textContainer)) { throw new ArgumentException($"{nameof(textContainer)} is already added to this project.", nameof(textContainer)); } if (fullPath != null) { if (_documentPathsToDocumentIds.ContainsKey(fullPath)) { throw new ArgumentException($"'{fullPath}' has already been added to this project."); } _documentPathsToDocumentIds.Add(fullPath, documentId); } _sourceTextContainersToDocumentIds = _sourceTextContainersToDocumentIds.Add(textContainer, documentInfo.Id); if (_project._activeBatchScopes > 0) { _documentsAddedInBatch.Add(documentInfo); } else { _project._workspace.ApplyChangeToWorkspace(w => { _project._workspace.AddDocumentToDocumentsNotFromFiles(documentInfo.Id); _documentAddAction(w, documentInfo); w.OnDocumentOpened(documentInfo.Id, textContainer); }); } } return(documentId); }
private void CreateSignatures( ITrackingSpan triggerSpan, int?selectedParameter) { _signatureMap = BidirectionalMap <SignatureHelpItem, Signature> .Empty; foreach (var item in _signatureHelpItems) { _signatureMap = _signatureMap.Add(item, new Signature(triggerSpan, item)); } this.SetCurrentParameterForAllItems(selectedParameter); }
/// <summary> /// Stops tracking a document in the RDT for whether we should attach to it. /// </summary> /// <returns>true if we were previously tracking it.</returns> private bool TryUntrackClosingDocument(uint docCookie, string moniker) { bool unregisteredRegistration = false; // Remove our registration changing handler before we call DetachFromDocument. Otherwise, calling DetachFromDocument // causes us to set the workspace to null, which we then respond to as an indication that we should // attach again. if (_docCookieToWorkspaceRegistration.TryGetValue(docCookie, out var registration)) { registration.WorkspaceChanged -= Registration_WorkspaceChanged; _docCookieToWorkspaceRegistration = _docCookieToWorkspaceRegistration.RemoveKey(docCookie); unregisteredRegistration = true; } DetachFromDocument(docCookie, moniker); return(unregisteredRegistration); }
public bool TryAddDocumentToWorkspace(string filePath, ITextBuffer buffer) { using (_gate.DisposableWait()) { if (_generatedFilenameToInformation.TryGetValue(filePath, out var fileInfo)) { Contract.ThrowIfTrue(_openedDocumentIds.ContainsKey(fileInfo)); // We do own the file, so let's open it up in our workspace var newProjectInfoAndDocumentId = fileInfo.GetProjectInfoAndDocumentId(_workspace, loadFileFromDisk: true); _workspace.OnProjectAdded(newProjectInfoAndDocumentId.Item1); _workspace.OnDocumentOpened(newProjectInfoAndDocumentId.Item2, buffer.AsTextContainer()); _openedDocumentIds = _openedDocumentIds.Add(fileInfo, newProjectInfoAndDocumentId.Item2); return(true); } } return(false); }
public LanguageSettingsPersister( IThreadingContext threadingContext, IVsTextManager4 textManager, IGlobalOptionService globalOptions) : base(threadingContext, assertIsForeground: true) { _textManager = textManager; _globalOptions = globalOptions; var languageMap = BidirectionalMap <string, Tuple <Guid> > .Empty; InitializeSettingsForLanguage(LanguageNames.CSharp, Guids.CSharpLanguageServiceId); InitializeSettingsForLanguage(LanguageNames.VisualBasic, Guids.VisualBasicLanguageServiceId); InitializeSettingsForLanguage(InternalLanguageNames.TypeScript, new Guid("4a0dddb5-7a95-4fbf-97cc-616d07737a77")); InitializeSettingsForLanguage("F#", new Guid("BC6DD5A5-D4D6-4dab-A00D-A51242DBAF1B")); InitializeSettingsForLanguage("Xaml", new Guid("CD53C9A1-6BC2-412B-BE36-CC715ED8DD41")); void InitializeSettingsForLanguage(string languageName, Guid languageGuid) { var languagePreferences = new LANGPREFERENCES3[1]; languagePreferences[0].guidLang = languageGuid; // The function can potentially fail if that language service isn't installed if (ErrorHandler.Succeeded(_textManager.GetUserPreferences4(pViewPrefs: null, pLangPrefs: languagePreferences, pColorPrefs: null))) { RefreshLanguageSettings(languagePreferences, languageName); languageMap = languageMap.Add(languageName, Tuple.Create(languageGuid)); } else { FatalError.ReportWithDumpAndCatch(new InvalidOperationException("GetUserPreferences4 failed"), ErrorSeverity.Diagnostic); } } _languageMap = languageMap; _textManagerEvents2Sink = ComEventSink.Advise <IVsTextManagerEvents4>(_textManager, this); }
public LanguageSettingsPersister( [Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider, IGlobalOptionService optionService) : base(assertIsForeground: true) { _textManager = (IVsTextManager4)serviceProvider.GetService(typeof(SVsTextManager)); _optionService = optionService; // TODO: make this configurable _languageMap = BidirectionalMap<string, Guid>.Empty.Add(LanguageNames.CSharp, Guids.CSharpLanguageServiceId) .Add(LanguageNames.VisualBasic, Guids.VisualBasicLanguageServiceId) .Add("TypeScript", new Guid("4a0dddb5-7a95-4fbf-97cc-616d07737a77")); foreach (var languageGuid in _languageMap.Values) { var languagePreferences = new LANGPREFERENCES3[1]; languagePreferences[0].guidLang = languageGuid; Marshal.ThrowExceptionForHR(_textManager.GetUserPreferences4(pViewPrefs: null, pLangPrefs: languagePreferences, pColorPrefs: null)); RefreshLanguageSettings(languagePreferences); } _textManagerEvents2Sink = ComEventSink.Advise<IVsTextManagerEvents4>(_textManager, this); }
private void CreateSignatures( ITrackingSpan triggerSpan, int? selectedParameter) { _signatureMap = BidirectionalMap<SignatureHelpItem, Signature>.Empty; foreach (var item in _signatureHelpItems) { _signatureMap = _signatureMap.Add(item, new Signature(triggerSpan, item)); } this.SetCurrentParameterForAllItems(selectedParameter); }
private void CreateSignatures( ITrackingSpan triggerSpan, int? selectedParameter) { _signatureMap = BidirectionalMap<SignatureHelpItem, Signature>.Empty; foreach (var item in _signatureHelpItems) { _signatureMap = _signatureMap.Add(item, new Signature(triggerSpan, item, GetParameterIndexForItem(item, selectedParameter))); } }
/// <summary> /// Stops tracking a document in the RDT for whether we should attach to it. /// </summary> /// <returns>true if we were previously tracking it.</returns> private bool TryUntrackClosingDocument(uint docCookie, string moniker) { bool unregisteredRegistration = false; // Remove our registration changing handler before we call DetachFromDocument. Otherwise, calling DetachFromDocument // causes us to set the workspace to null, which we then respond to as an indication that we should // attach again. WorkspaceRegistration registration; if (_docCookieToWorkspaceRegistration.TryGetValue(docCookie, out registration)) { registration.WorkspaceChanged -= Registration_WorkspaceChanged; _docCookieToWorkspaceRegistration = _docCookieToWorkspaceRegistration.RemoveKey(docCookie); unregisteredRegistration = true; } DetachFromDocument(docCookie, moniker); return unregisteredRegistration; }