async Task <IDocumentOptions> IDocumentOptionsProvider.GetOptionsForDocumentAsync(Document document, CancellationToken cancellationToken)
        {
            var mdws    = document.Project.Solution.Workspace as MonoDevelopWorkspace;
            var project = mdws?.GetMonoProject(document.Project.Id);

            var types = Ide.DesktopService.GetMimeTypeInheritanceChain(CSharpFormatter.MimeType);

            CSharpFormattingPolicy policy;
            TextStylePolicy        textpolicy;

            if (project == null)
            {
                textpolicy = PolicyService.InvariantPolicies.Get <TextStylePolicy> (types);
                policy     = PolicyService.InvariantPolicies.Get <CSharpFormattingPolicy> (types);
            }
            else
            {
                var policyParent = project.Policies;
                policy     = policyParent.Get <CSharpFormattingPolicy> (types);
                textpolicy = policyParent.Get <TextStylePolicy> (types);
            }
            var path = GetPath(document);
            ICodingConventionContext conventions = null;

            try {
                if (path != null)
                {
                    conventions = await EditorConfigService.GetEditorConfigContext(path, cancellationToken);
                }
            } catch (Exception e) {
                LoggingService.LogError("Error while loading coding conventions.", e);
            }
            return(new DocumentOptions(policy.CreateOptions(textpolicy), conventions?.CurrentConventions));
        }
            public CodingConventionsChangedWatcher(string filePath)
            {
                var codingConventionsManager = GetComponentModelService <ICodingConventionsManager>();

                _codingConventionContext = codingConventionsManager.GetConventionContextAsync(filePath, CancellationToken.None).Result;
                _codingConventionContext.CodingConventionsChangedAsync += (sender, e) =>
                {
                    _taskCompletionSource.SetResult(null);
                    return(Task.CompletedTask);
                };
            }
 internal void SetContext(ICodingConventionContext context)
 {
     if (this.context == context)
     {
         return;
     }
     if (this.context != null)
     {
         this.context.CodingConventionsChangedAsync -= UpdateContextOptions;
     }
     this.context = context;
     context.CodingConventionsChangedAsync += UpdateContextOptions;
     UpdateContextOptions(null, null);
 }
Beispiel #4
0
        async Task <IDocumentOptions> IDocumentOptionsProvider.GetOptionsForDocumentAsync(Document document, CancellationToken cancellationToken)
        {
            var mdws    = document.Project.Solution.Workspace as MonoDevelopWorkspace;
            var project = mdws?.GetMonoProject(document.Project.Id);

            var path = GetPath(document);
            ICodingConventionContext conventions = null;

            try {
                if (path != null)
                {
                    conventions = await EditorConfigService.GetEditorConfigContext(path, cancellationToken);
                }
            } catch (Exception e) {
                LoggingService.LogError("Error while loading coding conventions.", e);
            }
            return(new DocumentOptions(project?.Policies, conventions?.CurrentConventions));
        }
Beispiel #5
0
        protected override void OnFileNameChanged()
        {
            base.OnFileNameChanged();

            if (TextDocument == null)
            {
                return;
            }

            UpdateTextBufferRegistration();

            warnOverwrite = false;

            if (editorConfigContext != null)
            {
                editorConfigContext.CodingConventionsChangedAsync -= UpdateOptionsFromEditorConfigAsync;
                EditorConfigService.RemoveEditConfigContext(TextDocument.FilePath).Ignore();
                editorConfigContext = null;
            }

            if (FilePath != TextDocument.FilePath && !string.IsNullOrEmpty(TextDocument.FilePath))
            {
                AutoSave.RemoveAutoSaveFile(TextDocument.FilePath);
            }

            if (FilePath != null)             // Happens when a file is converted to an untitled file, but even in that case the text editor should be associated with the old location, otherwise typing can be messed up due to change of .editconfig settings etc.
            {
                TextDocument.Rename(FilePath);
            }

            // update the file type condition with the new path
            fileTypeCondition.SetFileName(FilePath);

            // TODO: Actually implement file rename support. Below is from old editor.
            //       Need to remove or update mimeType field, too.

            //if (this.WorkbenchWindow?.Document != null)
            //	textEditor.InitializeExtensionChain (this.WorkbenchWindow.Document);

            UpdateTextEditorOptions(null, null);
        }
Beispiel #6
0
        async Task UpdateTextEditorOptionsAsync()
        {
            UpdateLineNumberMarginOption();

            var foldMargin = PropertyService.Get <bool> ("ShowFoldMargin");

            Imports.OutliningManagerService.GetOutliningManager(TextView).Enabled = foldMargin;

            var newPolicyContainer = (Owner as IPolicyProvider)?.Policies;

            if (newPolicyContainer != policyContainer)
            {
                if (policyContainer != null)
                {
                    policyContainer.PolicyChanged -= PolicyChanged;
                }
                policyContainer = newPolicyContainer;
            }
            if (policyContainer != null)
            {
                policyContainer.PolicyChanged += PolicyChanged;
            }

            var newEditorConfigContext = await EditorConfigService.GetEditorConfigContext(FilePath, default);

            if (newEditorConfigContext != editorConfigContext)
            {
                if (editorConfigContext != null)
                {
                    editorConfigContext.CodingConventionsChangedAsync -= UpdateOptionsFromEditorConfigAsync;
                }
                editorConfigContext = newEditorConfigContext;
            }
            if (editorConfigContext != null)
            {
                editorConfigContext.CodingConventionsChangedAsync += UpdateOptionsFromEditorConfigAsync;
            }

            await UpdateOptionsFromEditorConfigAsync(null, null);
        }
Beispiel #7
0
        async Task UpdateTextEditorOptionsAsync()
        {
            UpdateLineNumberMarginOption();

            var newPolicyContainer = (Owner as IPolicyProvider)?.Policies;

            if (newPolicyContainer != policyContainer)
            {
                if (policyContainer != null)
                {
                    policyContainer.PolicyChanged -= PolicyChanged;
                }
                policyContainer = newPolicyContainer;
            }
            if (policyContainer != null)
            {
                policyContainer.PolicyChanged += PolicyChanged;
            }

            UpdateOptionsFromPolicy();

            var newEditorConfigContext = await EditorConfigService.GetEditorConfigContext(FilePath, default);

            if (newEditorConfigContext != editorConfigContext)
            {
                if (editorConfigContext != null)
                {
                    editorConfigContext.CodingConventionsChangedAsync -= UpdateOptionsFromEditorConfigAsync;
                }
                editorConfigContext = newEditorConfigContext;
            }
            if (editorConfigContext != null)
            {
                editorConfigContext.CodingConventionsChangedAsync += UpdateOptionsFromEditorConfigAsync;
            }

            await UpdateOptionsFromEditorConfigAsync(null, null);
        }
Beispiel #8
0
 protected override OptionSet ApplyFormattingOptions(OptionSet optionSet, ICodingConventionContext codingConventionContext)
 {
     return(_editorConfigOptionsApplier.ApplyConventions(optionSet, codingConventionContext.CurrentConventions, LanguageNames.CSharp));
 }
 protected abstract OptionSet ApplyFormattingOptions(OptionSet optionSet, ICodingConventionContext codingConventionContext);
        private Task UpdateGuidelinesFromCodingConventionAsync(ICodingConventionContext codingConventionContext, CancellationToken cancellationToken)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                return(Task.FromCanceled(cancellationToken));
            }

            StrokeParameters strokeParameters = null;

            if (codingConventionContext.CurrentConventions.TryGetConventionValue("guidelines_style", out string guidelines_style))
            {
                if (TryParseStrokeParametersFromCodingConvention(guidelines_style, out strokeParameters))
                {
                    _isUsingCodingConvention = true;
                    strokeParameters.Freeze();
                }
            }

            ICollection <Guideline> guidelines = null;

            if (codingConventionContext.CurrentConventions.TryGetConventionValue("guidelines", out string guidelinesConventionValue))
            {
                guidelines = ParseGuidelinesFromCodingConvention(guidelinesConventionValue, strokeParameters);
            }

            // Also support max_line_length: https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties#max_line_length
            if (codingConventionContext.CurrentConventions.TryGetConventionValue("max_line_length", out string max_line_length) && TryParsePosition(max_line_length, out int maxLineLengthValue))
            {
                (guidelines ?? (guidelines = new List <Guideline>())).Add(new Guideline(maxLineLengthValue, strokeParameters));
            }

            if (guidelines != null)
            {
                // Override 'classic' settings.
                _isUsingCodingConvention = true;

                // TODO: await JoinableTaskFactory.SwitchToMainThreadAsync();
                _view.VisualElement.Dispatcher.BeginInvoke(new Action <IEnumerable <Guideline> >(GuidelinesChanged), guidelines);
            }

            if (_isUsingCodingConvention && !s_sentEditorConfigTelemetry)
            {
                var eventTelemetry = new EventTelemetry("EditorConfig");
                if (!string.IsNullOrEmpty(guidelinesConventionValue))
                {
                    eventTelemetry.Properties.Add("Convention", guidelinesConventionValue);
                }

                if (!string.IsNullOrEmpty(max_line_length))
                {
                    eventTelemetry.Properties.Add(nameof(max_line_length), max_line_length);
                }

                if (!string.IsNullOrEmpty(guidelines_style))
                {
                    eventTelemetry.Properties.Add(nameof(guidelines_style), guidelines_style);
                }

                ColumnGuideAdornmentFactory.AddGuidelinesToTelemetry(eventTelemetry, guidelines);
                s_sentEditorConfigTelemetry = true;
            }

            return(Task.CompletedTask);
        }
 /// <summary>
 /// This partial method allows implementations of <see cref="EditorConfigDocumentOptionsProvider"/> (which are
 /// linked into both the in-process and out-of-process implementations as source files) to handle the creation
 /// of <see cref="ICodingConventionContext"/> in different ways.
 /// </summary>
 partial void OnCodingConventionContextCreated(DocumentId documentId, ICodingConventionContext context);
 internal void SetContext(ICodingConventionContext context)
 {
     this.context = context;
     context.CodingConventionsChangedAsync += UpdateContextOptions;
     UpdateContextOptions(null, null);
 }
Beispiel #13
0
 partial void OnCodingConventionContextCreated(DocumentId documentId, ICodingConventionContext context)
 {
     context.CodingConventionsChangedAsync += (sender, e) => HandleCodingConventionsChangedAsync(documentId, sender, e);
 }