Skip to content
This repository has been archived by the owner on Sep 24, 2020. It is now read-only.

How to implement C# 6.0+ support #532

Open
xwiz opened this issue Aug 26, 2017 · 4 comments
Open

How to implement C# 6.0+ support #532

xwiz opened this issue Aug 26, 2017 · 4 comments

Comments

@xwiz
Copy link

xwiz commented Aug 26, 2017

Hello,

We love SharpDevelop at our organization and prefer it many times better to any other that exists mainly because of the lightness and cost too. We would like to continue the development maybe in a new project/repo but need guidance on the most crucial place to start with (which I believe is C# 6.0+ support). Is it possible you can provide some guidelines/hint on where to start, what files to look at, what to understand, etc. Thank you

@dgrunwald
Copy link
Member

For C# 6 support in NRefactory, the answer is "pretty much the whole codebase".
I'm not sure which is easier -- add C# 7 support to NRefactory, or migrate SharpDevelop from NRefactory to Roslyn.

Keep in mind that NRefactory is nearly a full C# compiler frontend. The parser is shared with the Mono compiler, and NRefactory doesn't do any codegen, but otherwise it implements pretty much the full C# specification.
Any new language feature needs changes in at least the following steps:

  • for the parser, update the embedded mono compiler (is there an mcs that supports C# 7, or did mono replace their compiler with roslyn?)
  • add representation in the NRefactory syntax tree
  • CSharpParser: convert from the mono compiler's syntax tree to the NRefactory syntax tree
  • ResolveVisitor: add semantic analysis for the new language construct
    • if you want to accurately represent the resulting semantics, you'll likely need new constructs in the semantic tree (tree of ResolveResults)
  • update the OutputVisitor so that refactorings can round-trip the new language construct

Of course, not all language changes are new syntactic constructs... there's plenty of stuff in C# 7 that requires touching various other stuff in NRefactory (type inference, overload resolution, ...). But you can ignore those as long as you don't need code completion, go to definition, and find references to be perfectly accurate.

@xwiz
Copy link
Author

xwiz commented Aug 26, 2017

Great, this sounds like lots of help already. I was also already on the path of plugging in Roslyn and it seems like the sanest option for the long term. For the short term, we will explore the repo to get an understanding of how tightly it's still coupled with SharpDevelop, and if we can reduce it to an interface which anyone can use to plug in whatever compiler they want, that would be an awesome start.

@ashuvviet
Copy link

Hello @xwiz , @dgrunwald , can you guys confirm if you have already converted or any progress on c#7 support NRefactory, or is it still under development to migrate to Roslyn? do you have some information?

@dgrunwald
Copy link
Member

No one is working on NRefactory anymore. Anyone still stuck on NRefactory should migrate to Roslyn.

Of the main open-source NRefactory users I am aware of:

  • SharpDevelop is discontinued and will never get C# 6 support.
  • MonoDevelop replaced NRefactory with Roslyn a long time ago.
  • ICSharpCode.CodeConverter replaced NRefactory with Roslyn a long time ago.
  • ILSpy is still using a syntax tree based on NRefactory, and updated that syntax tree for C# 9. However, it only updated the parts of NRefactory needed for the decompiler, and deleted all other parts. In particular, it deleted the parser and resolve visitor.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants