Using Resharper's 'Search with Pattern' mode, I've been trying to do the simple task of finding and replacing a using statement, but it doesn't appear to let me do this, it complains that the "Pattern is ambiguous".
What's the problem here?
I realise I can use Visual Studio's own find and replace tool, but I have a lot of files to change, and I know from experience that Resharper gives me more control over finding and replacing code (and also because I'm curious as to what the issue is here).
"Search by Pattern" is a powerful tool for searching by regex or other patterns.
The prompt is due to the engine interpreting your query as a very open-ended Regular Expression.
For a basic search & replace such as yours, I would use the built-in tools which Visual Studio provides.
Additional and very important note: The warning is actually "Pattern is ambiguos [sic]"
Related
Problem:
My company recently decided to improve coding standards. One of the proposals has been to add a blank line after an 'if' statement withput brackets. E.g.:
if(condition)
statement;
statement;
This kind of construct is widely used in our codebase and adding a blank line would increase readability. Now it is my job to find a way to bring VS13 to indicate this in inspection.
Attempted Solutions:
At first I tried to solve this by using Resharper.
In Code Editing -> C# -> Formatting Style -> Blank Lines is no such option available.
A pattern (added in Code Inspection -> Custom Patterns) does find the 'if' statements just fine but I cannot add a blank line as this is, according to the Internet, out of scope of that functionality.
At that point I searched for another solution and found StyleCop. The first Version I tried was 'StyleCop by Resharper' (here). As far as I can tell StyleCop does not support this feature either. But there is documentation explaining how to add custom rules in another Version of Stylecop. So I thought that something like this might also be possible in 'StyleCop by Resharper'. But unfortunately there is no documentation anywhere.
I then used Visual StyleCop and removed the Resharper Version. I also downloaded the VisualStudio Extension for Visual StyleCop and implemented my custom rule. The extension even found said rule... but it did not mark anything in my solution and manual scans were cancelled early without an error.
On a side note: I apparently cannot use StyleCopAnalyzers since it is not compatible with VS versions below 2015.
Question:
How can this be solved? A solution that added a custom rule to 'StyleCop by Resharper' would be the most elegant, I think. But really, at this point any suggestion would be helpful.
I think the option to have a blank line after a single If line is under Code Editing > C# > Formatting Style > Blank Lines in Code > After Statements with control transfer and set it to 1
AFAIK the only way to add new custom rules to Stylecop (doesn't matter if is the one from R# is by doing the following -> https://www.planetgeek.ch/2009/07/19/custom-stylecop-rules-2/
I'm happily developing a language in ANTLR 4.4 / ANTLR4CS, and I'd like to start integrating my language into an IDE. The natural place for me feels like integrating it into Visual Studio. It occurs to me that someone might have figured out a general way to plug an ANTLR lexer into the Visual Studio syntax highlighting system, or ANTLR parsers into an MSBuild task such that errors appear in the Visual Studio error list.
Is there any kind of starting point, base package, plugin system, or similar which lets you integrate an ANTLR4CS language with Visual Studio's language support mechanisms?
Alternatively, has anyone had any success building, say, a Sublime Text build system / language def automatically from their grammar?
#Lucas Trzesniewski wrote:
I did this by reparsing the whole file every time, doing it on a line-by line basis was too much of a PITA for my needs (and our DSL files are small so it works fine).
I don't know if it'll be suitable for your needs, but you can implement a single file generator from a VS extension. The Generate method takes a IVsGeneratorProgress parameter which lets you report errors easily.
I want to add support for syntax highlighting for lex and yacc-files in Visual Studio 2010.
How can I do this?
Following the given link to Syntax Coloring leads to another, more pertinent page Implementing Syntax Coloring, where it is noted
Visual Studio does not specify a parser interface, and parser implementation is completely up to you. However, a default parser implementation is provided in the Visual Studio Language Package project. For managed code, the managed package framework (MPF) provides complete support for colorizing text.
Depending on what you want:
trivial, coloring only the C code portions of the lex/yacc files
much harder, coloring the patterns so that one can make sense of them
you could in principle make a parser using just lex (yacc isn't necessary). For yacc files, that's not so hard, but for lex there's the complication of regular expressions. vi-like-emacs does that and while the interface differs in detail, conceptually it's similar. Reading the lexers might give you some ideas how to apply that approach:
lex syntax filter
yacc syntax filter
There is documentation from Microsoft on integrating yacc/bison & flex/lex with Visual Studio. Although a URL only link is discouraged on SO, its best to go to the source for this kind of detailed information:
https://msdn.microsoft.com/en-us/library/aa730877(VS.80).aspx#vccustombr_topic3
It lays out all the steps necessary for integrating with the build tools. Syntax highlighting is covered elsewhere as described in Add a new language to Visual Studio 2010 with syntax highlighting and intellisense. In particular the guidance for syntax colouring can be found here: https://msdn.microsoft.com/en-us/library/bb166778(v=vs.100).aspx.
However, I'm not aware of anyone who has published extra colouring rules for the grammar specific components of flex and yacc. However, most of the body of flex and yacc files are written in C or C++ for which there are syntax highlighting rules that can be applied, and suit most peoples needs.
Is it possible and if so how, to make Visual Studio highlight dynamic expressions in code?
When I just hovered above some code, visual studio told me it was a dynamic expression. This made me realize I made a mistake in my code and used one dynamic too many. But I also realized that if I had not hovered, a 'huge swath' of dynamic code that was supposed to be static would have escaped.
So I wondered if it is possible to make Visual Studio change the background color of dynamic expressions, so those pieces will be clearly recognizable.
[edit]
With dynamic expressions I mean the use of the dynamic keyword in regular code.
You would need an Extension. You can create your own, but I would suggest getting pre-built ones.
Visual Studio has a lot of extensions lately, because of it's popularity.
There are many options I could suggest, but many are rather buggy, so I would suggest using one of the safer, more well known ones like Resharper (my all time favorite and that of many others as well)
I also like JustCode.
There are so many others available though, and if you want to find them, cruise down the Visual Studio Gallery like Morvader said.
Visual Studio Gallery
EDIT:
2 notes I forgot to mention:
Dynamic Intellisense is included in Resharper
Dynamic Highlighting is included as well. If you want to modify the color from the default light blue you can go to Tools->Options...->Environments->Fonts and Colors->Display items->ReSharper Late Bound Identifier
Also make sure that in Resharper->Options...->Code Inspection->Settings "Enable code analysis" and "Color identifiers" are checked.
I hope this is a valid question: how does intellisense work in VS2008? I'm after what is known about the algorithm it uses to find the suggestions, when exactly it pops up (the "." is just one obvious trigger), how its behavior can be modified if at all possible, etc.
To put this question into context: The main issue I'm trying to resolve is how to activate and deactivate intellisense in portions of the editor screen and how to modify where it searches to populate the suggestion box.
All information is welcome.
Take a look at this DIY Intellisense article on CodeProject.
It's more fun to reverse-engineer it, though. Let's consider the problem:
you need to identify the words of interest
you need to find the options possible
you need to present them
Now, the first step means you have to parse the code. You've got the C/C** keywords, you pre-parse the various function and class declarations, and load them into some kind of data structure. Then you parse the code and store the class, variable, etc names and put them in the same data structure.
The second step means you want a data structure which efficiently can search for a partial word and get all the words that have that prefix. You can do that with regular expressions, but that's not very efficient. An efficient data structure for that kind of search is a trie, which is discussed here on SO .
Once you have the list of possibilities, you just present it. You probably want to keep a reference to the root of the tree of possibilities so you can search them out in real time as someone types more letters.
Eclipse also has this feature and it is an open source project. Why not check out how Eclipse does it by actually looking at the code?
This question is too broad. Since there are a number of different languages the VS IDE supports out of the box AND there are N number of DSL and IDE enhancements that support alternative intellisense this implies a number of answers. If you are speaking about C# specifically then See the Tools | Options | Text Editor | C# | Intellisense area to see the available options of completion options. As far as the algorithm[s] used, you would be looking for the metadata of assemblies, copious caching of type members, MRU list for last member chosen for specific type, etc. If you have a more specific question, I'd suggest you clarify.
See the example of a DSL (ironpython) and its implementation here.
I haven't seen any text editor in VS that limits where IntelliSense shows up. It's all language specific. If your cursor is located at a point where IntelliSense might contribute to a valid token, that's when it will be used.
I believe there is some interaction with the project system being used, but that's as far as I know. I also believe there is a sample project system in the Visual Studio SDK, and that might give you an idea.
For such cases I sometimes use my own version of InteliSense that I developed for AutoHotKey when I want specific behavior. The point of this script is that it can be used with any editor, or basically any control accepting text. It works by recording text input and interpreting it upon syntax file.
You can perhaps use it as a base for the thing you want to achieve. I used ISense succesifully with several languages that don't have such thing, like Csound or even batch scripts. It will be possible to extend it to support C# using input monitoring in combination with Reflection.
Anyway, with AHK you can even control VS intelissense by "taking" the list of items it presents and filter it, or similar things. You may have some small problems with process boundaries but nothing that cant be fixed.
The intellisense ius generally, AFAIK, implemented using different methods. I read that Delphi is so fast that it implements isense by recompiling the project on each token and thats the reason C++ Builder didn't have isense as its compiling very slow.
As to your how to change where it looks question, short answer is, you can't. Intellisense for the most part is provided by reflection of assemblies included in your project ( and some other tricks with C++ ). What you are getting is a result of VS processing through all the assemblies you have included and all assemblies from the GAC.
That said, if you want to provide explicit intellisense results from a project you are working on, look into IVsContextualIntellisenseFilterProvider
Finally, for some insight into the behind the scenes process, check this blog post