gojimmypi / GcodeLanguageExtension

Visual Studio g-code syntax highlighter for CNC and 3DPrinters
MIT License
2 stars 1 forks source link

No highlights in VS2015 #5

Open gojimmypi opened 4 years ago

gojimmypi commented 4 years ago

As noted in https://github.com/gojimmypi/GcodeLanguageExtension/issues/2#issuecomment-523359226 there is no G-Code syntax highlighting in VS2015, although the same code appears to work just fine in VS2017 and VS2019.

Debugging from VS2015 does show this curious error that is not manifested when not debugging:

  <entry>
    <record>630</record>
    <time>2019/09/01 17:27:19.658</time>
    <type>Error</type>
    <source>Editor or Editor Extension</source>
    <description>System.ComponentModel.Composition.ImportCardinalityMismatchException: Duplicate EditorFormatDefinition exports with identical name attributes exist. Duplicate name is CTN_Gcode_Undefined</description>
  </entry>

I've tried removing all extensions and removing the CTN_ prefix, yet the problem persists.

gojimmypi commented 4 years ago

Here's the same code being debugged in VS2015. For some reason it generates this error:

System.InvalidOperationException was unhandled
Message: An unhandled exception of type 'System.InvalidOperationException' occurred in PresentationCore.dll
Additional information: The visual tree has been changed during a 'VisualTreeChanged' event.

image

I suspect there's a newer class library referenced by VS2017/VS2019 that VS2015 doesn't like.

The referenced generic help link is indeed pretty generic:

The exception that is thrown when a method call is invalid for the object's current state.

InvalidOperationException is used in cases when the failure to invoke a method is caused by reasons other than invalid arguments. Typically, it is thrown when the state of an object cannot support the method call.
gojimmypi commented 4 years ago

And indeed the single change of allowing multiple files with different extensions seems to be the source of this problem. :/

Simply changing the GcodeClassifierProvider File FileExtension attribute

From

[FileExtension(".gcode")] 

to

[FileExtension(".gcode;.nc;.mpt;.mpf")] 

...appears to be a breaking change for VS2015.

gojimmypi commented 4 years ago

Hello @DavidHopkinsFbr - check out version 0.1.6.0 - this version should fix the issue of no highlighting in VS2015. The problem seems to be the comma-separated file extensions are not supported in VS2015. I replaced the code with duplicate sections that each have a single file extension attribute:

        [Export]
        [Name("Gcode")]
        [BaseDefinition("code")]
        [BaseDefinition("projection")]
        internal static ContentTypeDefinition GcodeContentType = null;

        [Export]
        [FileExtension(".gcode")] // semi-colon delimited file extensions work only in VS2017/2019 - so we create multiple FileExtensionToContentTypeDefinition 
        [ContentType("Gcode")]
        [BaseDefinition("code")]
        [BaseDefinition("projection")]
        internal static FileExtensionToContentTypeDefinition GcodeFileType = null;

        [Export]
        [FileExtension(".mpf")] // semi-colon delimited file extensions work only in VS2017/2019 - so we create multiple FileExtensionToContentTypeDefinition 
        [ContentType("Gcode")]
        [BaseDefinition("code")]
        [BaseDefinition("projection")]
        internal static FileExtensionToContentTypeDefinition GcodeFileTypeMPF = null;

        [Export]
        [FileExtension(".mpt")] // semi-colon delimited file extensions work only in VS2017/2019 - so we create multiple FileExtensionToContentTypeDefinition 
        [ContentType("Gcode")]
        [BaseDefinition("code")]
        [BaseDefinition("projection")]
        internal static FileExtensionToContentTypeDefinition GcodeFileTypeMPT = null;

        [Export]
        [FileExtension(".nc")] // semi-colon delimited file extensions work only in VS2017/2019 - so we create multiple FileExtensionToContentTypeDefinition 
        [ContentType("Gcode")]
        [BaseDefinition("code")]
        [BaseDefinition("projection")]
        internal static FileExtensionToContentTypeDefinition GcodeFileTypeNC = null;