public CommentAnalyzer(ISolution solution, IContextBoundSettingsStore settingsStore) { _settingsStore = settingsStore; _solution = solution; _xmlDocumentationSettings = _settingsStore.GetKey <XmlDocumentationSettings>(SettingsOptimization.OptimizeDefault); _identifierSettings = _settingsStore.GetKey <IdentifierSettings>(SettingsOptimization.OptimizeDefault); _xmlDocumentationSpellChecker = SpellCheckManager.GetSpellChecker( _settingsStore, _solution, this._xmlDocumentationSettings.DictionaryName == null ? null : this._xmlDocumentationSettings.DictionaryNames ); }
public static void ReflowAndRetagCommentBlockNode(ISolution solution, IProgressIndicator progress, IDocCommentBlockNode docCommentBlockNode) { if (docCommentBlockNode == null) { return; } // Get the settings. IContextBoundSettingsStore settingsStore = Shell.Instance.GetComponent <ISettingsStore>().BindToContextTransient(ContextRange.ApplicationWide); XmlDocumentationSettings settings = settingsStore.GetKey <XmlDocumentationSettings>(SettingsOptimization.OptimizeDefault); ReflowAndRetagSettings reflowSettings = settingsStore.GetKey <ReflowAndRetagSettings>(SettingsOptimization.OptimizeDefault); int maxLength = settings.MaxCharactersPerLine; // Get the comment block owner (ie the part of the declaration which will own the comment). IDocCommentBlockOwnerNode ownerNode = docCommentBlockNode.GetContainingNode <IDocCommentBlockOwnerNode>(); // If we didn't get an owner then give up if (ownerNode == null) { return; } // Get a factory which can create elements in the C# docs //CSharpElementFactory factory = CSharpElementFactory.GetInstance(ownerNode.GetPsiModule()); // Calculate line offset where /// starts and add 4 for the slashes and space int startPos = CalcLineOffset(ownerNode) + 4; // Create a new comment block with the adjusted text IDocCommentBlockNode comment = docCommentBlockNode; //factory.CreateDocCommentBlock(text); string reflownText = new XmlCommentReflower(settings, reflowSettings).ReflowAndRetag(comment, maxLength - startPos); // If the xml was malformed then the comment will now be empty - detect this and do nothing if (string.IsNullOrEmpty(reflownText)) { return; } /*comment = factory.CreateDocCommentBlock(reflownText); * * // And set the comment on the declaration. * ownerNode.SetDocCommentBlockNode(comment);*/ SetDocComment(ownerNode, reflownText, solution); }
/// <summary> /// Execute this stage of the process. /// </summary> /// <param name="commiter">The function to call when we've finished the stage to report the results.</param> public void Execute(Action <DaemonStageResult> commiter) { IFile file = _daemonProcess.SourceFile.GetTheOnlyPsiFile(CSharpLanguage.Instance); if (file == null) { return; } var consumer = new DefaultHighlightingConsumer(this, _settingsStore); var commentSettings = _settingsStore.GetKey <CommentSettings>(SettingsOptimization.OptimizeDefault); foreach (var commentNode in file.Descendants <ICSharpCommentNode>()) { CheckComment(commentNode, consumer, commentSettings); } try { commiter(new DaemonStageResult(consumer.Highlightings)); } catch { // Do nothing if it doesn't work. } }
public static void ReFlowCommentBlockNode(ISolution solution, IProgressIndicator progress, IDocCommentBlockNode docCommentBlockNode) { if (docCommentBlockNode == null) { return; } // Get the settings. IContextBoundSettingsStore settingsStore = Shell.Instance.GetComponent <ISettingsStore>().BindToContextTransient(ContextRange.ApplicationWide); XmlDocumentationSettings settings = settingsStore.GetKey <XmlDocumentationSettings>(SettingsOptimization.OptimizeDefault); ReflowAndRetagSettings reflowSettings = settingsStore.GetKey <ReflowAndRetagSettings>(SettingsOptimization.OptimizeDefault); int maxLength = settings.MaxCharactersPerLine; IDocCommentBlockOwnerNode ownerNode = docCommentBlockNode.GetContainingNode <IDocCommentBlockOwnerNode>(); // If we didn't get an owner then give up if (ownerNode == null) { return; } // Get a factory which can create elements in the C# docs //CSharpElementFactory factory = CSharpElementFactory.GetInstance(ownerNode.GetPsiModule()); // Calculate line offset where /// starts and add 3 for each // slash. int startPos = CalcLineOffset(ownerNode) + 3; // Create a new comment block with the adjusted text IDocCommentBlockNode comment = docCommentBlockNode; //factory.CreateDocCommentBlock(text); // Work out if we have a space between the /// and <summary> string reflownText = new XmlCommentReflower(settings, reflowSettings).Reflow(comment, maxLength - startPos); //comment = factory.CreateDocCommentBlock(reflownText); SetDocComment(ownerNode, reflownText, solution); // And set the comment on the declaration. //ownerNode.SetDocCommentBlockNode(comment); }
public void Execute(Action <DaemonStageResult> action) { IPsiModule module = _file.GetPsiModule(); ResXSettings settings = _settingsStore.GetKey <ResXSettings>(SettingsOptimization.OptimizeDefault); IAttributesSet moduleAttributes = _file.GetSolution().GetPsiServices().Symbols.GetModuleAttributes(module); string defaultResXDic = "en-US"; IList <IAttributeInstance> attributes = moduleAttributes .GetAttributeInstances(new ClrTypeName(typeof(NeutralResourcesLanguageAttribute).FullName), false); if (attributes != null && attributes.Count > 0 && attributes[0].PositionParameter(0).ConstantValue.Value != null) { defaultResXDic = attributes[0].PositionParameter(0).ConstantValue.Value.ToString(); } #if RESHARPER20173 var consumer = new DefaultHighlightingConsumer(_daemonProcess.SourceFile); #else var consumer = new DefaultHighlightingConsumer(this, _settingsStore); #endif ISpellChecker checker = SpellCheckManager.GetSpellChecker(_settingsStore, _file, defaultResXDic); if (checker != null) { foreach (IXmlToken token in getStringsToCheck()) { WordLexer lexer = new WordLexer(token.GetText()); lexer.Start(); while (lexer.TokenType != null) { if (SpellCheckUtil.ShouldSpellCheck(lexer.TokenText, settings.CompiledWordsToIgnore) && !checker.TestWord(lexer.TokenText, false)) { DocumentRange docRange = token.GetDocumentRange(); TextRange textRange = new TextRange(docRange.TextRange.StartOffset + lexer.TokenStart, docRange.TextRange.StartOffset + lexer.TokenEnd); DocumentRange range = new DocumentRange(docRange.Document, textRange); ResXSpellHighlighting highlighting = new ResXSpellHighlighting(lexer.TokenText, _file, checker, range, _settingsStore); consumer.AddHighlighting(highlighting, range); } lexer.Advance(); } } } action(new DaemonStageResult(consumer.Highlightings)); }
CachedXmlDocInspectionsSettings ICachedSettingsReader <CachedXmlDocInspectionsSettings> .ReadData(IContextBoundSettingsStore store) { var settings = store.GetKey <XmlDocInspectionsSettings>(_settingsOptimization); var includeAttributeClrTypeNames = (from part in settings.IncludeAttributeFullNames.Split(',') let fullName = part.Trim() where !string.IsNullOrEmpty(fullName) select new ClrTypeName(fullName)).ToList(); return(new CachedXmlDocInspectionsSettings(settings, includeAttributeClrTypeNames)); }
/// <summary> /// Invoked by ReSharper each time it wants us to perform some background processing /// of a file. /// </summary> /// <param name="process">Provides information about and services relating to the /// work we are being asked to do.</param> /// <param name="settings">Settings information.</param> /// <param name="processKind">The kind of processing we're being asked to do.</param> /// <param name="file">The file to be processed.</param> /// <returns>A process object representing the work, or null if no work will be done.</returns> protected override IDaemonStageProcess CreateProcess( IDaemonProcess process, IContextBoundSettingsStore settings, DaemonProcessKind processKind, ICSharpFile file) { if (process == null) { throw new ArgumentNullException("process"); } // StyleCop's daemon stage looks for a processKind of DaemonProcessKind.OTHER // and does nothing (returns null) if it sees it. This turns out to prevent // highlights from showing up when you ask ReSharper to inspect code issues // across the whole solution. I'm not sure why StyleCop deliberately opts out // of it. Perhaps something goes horribly wrong, but I've not seen any sign // of that yet, and we really do want solution-wide inspection to work. try { // I guess the base class checks that this is actually a C# file? if (!IsSupported(process.SourceFile)) { return(null); } // StyleCop checks to see if there are already any errors in the file, and if // there are, it decides to do nothing. // TODO: Do we need to do that? // TODO: We should probably check for exemptions, e.g. generated source files. } catch (ProcessCancelledException) { return(null); } // TODO: should we get an injected ISettingsOptimization? var orderUsingSettings = settings.GetKey <OrderUsingsSettings>(SettingsOptimization.DoMeSlowly); OrderUsingsConfiguration config = null; if (!string.IsNullOrWhiteSpace(orderUsingSettings.OrderSpecificationXml)) { config = ConfigurationSerializer.FromXml(new StringReader(orderUsingSettings.OrderSpecificationXml)); } return(new OrderUsingsDaemonStageProcess(process, file, config)); }
/// <summary> /// Invoked by ReSharper each time it wants us to perform some background processing /// of a file. /// </summary> /// <param name="process">Provides information about and services relating to the /// work we are being asked to do.</param> /// <param name="settings">Settings information.</param> /// <param name="processKind">The kind of processing we're being asked to do.</param> /// <param name="file">The file to be processed.</param> /// <returns>A process object representing the work, or null if no work will be done.</returns> protected override IDaemonStageProcess CreateProcess( IDaemonProcess process, IContextBoundSettingsStore settings, DaemonProcessKind processKind, ICSharpFile file) { if (process == null) { throw new ArgumentNullException("process"); } // StyleCop's daemon stage looks for a processKind of DaemonProcessKind.OTHER // and does nothing (returns null) if it sees it. This turns out to prevent // highlights from showing up when you ask ReSharper to inspect code issues // across the whole solution. I'm not sure why StyleCop deliberately opts out // of it. Perhaps something goes horribly wrong, but I've not seen any sign // of that yet, and we really do want solution-wide inspection to work. try { // I guess the base class checks that this is actually a C# file? if (!IsSupported(process.SourceFile)) { return null; } // StyleCop checks to see if there are already any errors in the file, and if // there are, it decides to do nothing. // TODO: Do we need to do that? // TODO: We should probably check for exemptions, e.g. generated source files. } catch (ProcessCancelledException) { return null; } // TODO: should we get an injected ISettingsOptimization? var orderUsingSettings = settings.GetKey<OrderUsingsSettings>(SettingsOptimization.DoMeSlowly); OrderUsingsConfiguration config = null; if (!string.IsNullOrWhiteSpace(orderUsingSettings.OrderSpecificationXml)) { config = ConfigurationSerializer.FromXml(new StringReader(orderUsingSettings.OrderSpecificationXml)); } return new OrderUsingsDaemonStageProcess(process, file, config); }
//private const int MAX_LENGTH_TO_SKIP = 0; public IdentifierSpellCheckAnalyzer(ISolution solution, IContextBoundSettingsStore settingsStore, IPsiSourceFile file) { _identifierSettings = settingsStore.GetKey <IdentifierSettings>(SettingsOptimization.OptimizeDefault); _settingsStore = settingsStore; _solution = solution; _policyProvider = file.GetPsiServices().Naming.Policy.GetPolicyProvider(CSharpLanguage.Instance, file, _settingsStore); _identifierSpellChecker = SpellCheckManager.GetSpellChecker( _settingsStore, _solution, _identifierSettings.DictionaryName == null ? null : _identifierSettings.DictionaryNames ); }
/// <inheritdoc/> public void Process( IPsiSourceFile sourceFile, IRangeMarker rangeMarker, CodeCleanupProfile profile, IProgressIndicator progressIndicator) { IPsiServices psiServices = sourceFile.GetPsiServices(); IPsiFiles psiFiles = psiServices.Files; IContextBoundSettingsStore settings = sourceFile.GetSettingsStore(); var orderUsingSettings = settings.GetKey <OrderUsingsSettings>(SettingsOptimization.DoMeSlowly); OrderUsingsConfiguration config = null; if (!string.IsNullOrWhiteSpace(orderUsingSettings.OrderSpecificationXml)) { config = ConfigurationSerializer.FromXml(new StringReader(orderUsingSettings.OrderSpecificationXml)); } if (config == null) { return; } var file = psiFiles.GetDominantPsiFile <CSharpLanguage>(sourceFile) as ICSharpFile; if (file == null) { return; } if (!profile.GetSetting(DescriptorInstance)) { return; } file.GetPsiServices().Transactions.Execute( "Code cleanup", () => { using (_shellLocks.UsingWriteLock()) { CleanUsings(file, config); WalkNamespaceDeclarations(file.NamespaceDeclarations, config); } }); }
protected override IDaemonStageProcess CreateProcess( IDaemonProcess process, IContextBoundSettingsStore settings, DaemonProcessKind processKind, ICSharpFile file) { if (IsSupported(process.SourceFile) == false) { return(null); } var exceptionalSettings = settings.GetKey <ExceptionalSettings>(SettingsOptimization.OptimizeDefault); exceptionalSettings.InvalidateCaches(); ServiceLocator.Process = process; ServiceLocator.Settings = exceptionalSettings; ServiceLocator.StageProcess = new ExceptionalDaemonStageProcess(file, process.SourceFile, settings); return(ServiceLocator.StageProcess); }
/// <summary> /// Execute this stage of the process. /// </summary> /// <param name="commiter">The function to call when we've finished the stage to report the results.</param> public void Execute(Action <DaemonStageResult> commiter) { IFile file = _daemonProcess.SourceFile.GetTheOnlyPsiFile(CSharpLanguage.Instance); if (file == null) { return; } StringSettings stringSettings = _settingsStore.GetKey <StringSettings>(SettingsOptimization.OptimizeDefault); if (!_daemonProcess.FullRehighlightingRequired) { return; } CommentAnalyzer commentAnalyzer = new CommentAnalyzer(_solution, _settingsStore); IdentifierSpellCheckAnalyzer identifierAnalyzer = new IdentifierSpellCheckAnalyzer(_solution, _settingsStore, _daemonProcess.SourceFile); #if RESHARPER20173 var consumer = new DefaultHighlightingConsumer(_daemonProcess.SourceFile); #else var consumer = new DefaultHighlightingConsumer(this, _settingsStore); #endif foreach (var classMemberDeclaration in file.Descendants <IClassMemberDeclaration>()) { CheckMember(classMemberDeclaration, consumer, commentAnalyzer, identifierAnalyzer); } if (_daemonProcess.InterruptFlag) { return; } try { commiter(new DaemonStageResult(consumer.Highlightings)); } catch { // Do nothing if it doesn't work. } }
public MspecProviderSettings ReadData(Lifetime lifetime, IContextBoundSettingsStore store) { return((MspecProviderSettings)store.GetKey(KeyExposed, null, SettingsOptimization) !); }
public static ReSharperHelperSettings GetSettings([NotNull] IContextBoundSettingsStore store) { return(store.GetKey <ReSharperHelperSettings>(SettingsOptimization.OptimizeDefault)); }
public UnitySolutionHelper(ISettingsStore settingsStore) { IContextBoundSettingsStore boundSettings = settingsStore.BindToContextTransient(ContextRange.ApplicationWide); m_unitySettings = boundSettings.GetKey <UnitySettings>(SettingsOptimization.DoMeSlowly); }