How to implement C# 6.0+ support #532

Open
opened 2017-08-26 04:20:23 -05:00 by xwiz · 4 comments
xwiz commented 2017-08-26 04:20:23 -05:00 (Migrated from github.com)

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

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 commented 2017-08-26 06:57:41 -05:00 (Migrated from github.com)

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.

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](https://github.com/icsharpcode/NRefactory/tree/master/ICSharpCode.NRefactory.CSharp/Ast) * 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 commented 2017-08-26 08:20:43 -05:00 (Migrated from github.com)

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.

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 commented 2020-09-24 02:16:58 -05:00 (Migrated from github.com)

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?

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 commented 2020-09-24 02:43:06 -05:00 (Migrated from github.com)

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.
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.
This discussion has been locked. Commenting is limited to contributors.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-icsharpcode/NRefactory#532
No description provided.