Sublime Forum

[Solved] [Bug - 3111] - C called functions not highlighted correctly

#1

I noticed that in the last build (3111) that functions called by another function are not higlighted correctly, unless I use the Monokai theme.
Surprisingly, I noticed this is true only for some C code of mine, where this is “broken”; tested on a “simple” C example file, it works fine.

0 Likes

#2

However, no test case is given.

2 Likes

#3

Here it is: this is with the Monokai color scheme (working):

…and this is with the Monokai bright color scheme (broken):

P.S. By the way, there are some (minor) differences as well, for instance the pointers (&, *) are highlighted, and the equal symbol is highlighted, as well…

0 Likes

#4

It looks like both Monokai and Monokai bright miss some scopes.
Unfortunately, to fix it, you have to make that theme “customized,” i.e., add missing scopes.

  • To customize/modify your own theme, you may use PackageResourceViewer to find your .tmTheme file. It’s in Color Scheme - Default package.
  • To find scope at cursor position, press ctrl+alt+shift+P.

Or, maybe, just use a good theme which already exists.

0 Likes

#5

It’s just that these ship with ST by default and thus should be fixed upstream, making this still a valid report.

@Nova, for easier reproduction, please include the sample code as text too. You can wrap it in triple-fenced blocks or indent it by four spaces.

0 Likes

#6

Monokai not highlighting operator chars is deliberate - see Dev Build 3110

1 Like

#7

We likely need to pull Monokai Bright in sync with Monokai. I haven’t looked at what is supposed to be different, but I imagine we’ve just implemented some of the recent tweaks just to the main variant.

1 Like

#8

I lost the original source code file I used for the test. Anyhow, here is part of it:

#include <stdio.h>
#include <stdlib.h>

char *decimal_to_binary(int);

void TestMe( Uint8 *u8Test )
{
    if( CallThisFunction( u8Test ))
    {
        CallAnotherFunction( u8Test );
    }
}

void main( void )
{
    int n, c, k;
    char *pointer;

    printf("Enter an integer in decimal number system\n");
    scanf("%d", &n);

    pointer = decimal_to_binary(n);
    printf("Binary string of %d is: %s\n", n, t );

    free( pointer );
    return 0; 
}

Seems that “library functions” (printf, scanf, …) are correctly highlighted, while custom functions are not.
Thank you all, for the quick reply.

1 Like

#9

It is just the scope variable.function missing in the theme.

0 Likes

#10

I found another problem, with the same “scope”.
Some #ifdef is breaking the parsing of function - function calls in C syntax; here is (part of) my code for example:

static void MCU_SetSysClock()
{
    /* PLL prescalers configuration settings */
#if( EXTAL == 40000 )                       /* 40 MHz */

    #if( PLL_0_CLOCK == 200000 )
        #define PLL_MFD         40
        #define PLL_PREDIV      4
        #define PLL_RFD_PHI     2
        #define PLL_RFD_PHI1    10      // PLL0_PH1 = 40MHz
    #else
        #error "Unsupported PLL0 clock frequency (PLL_0_CLOCK)"
    #endif

    /* Note: configuration below assumes use of PLL0_PH1 @40MHz as reference */
    #if( PLL_1_CLOCK == 260000 )
        #define PLL_1_MFD       26
        #define PLL_1_RFD_PHI   2

        /* Progressive clock switching values (ref. MPC5777M_PCS.xlsx) */
        #define PCS_SDUR_VAL    0x10
        #define PCS_PLL1_RATE   0x30
        #define PCS_PLL1_INIT   0x4DF
        #define PCS_PLL1_DIVE   0x3F79
        #define PCS_PLL1_DIVS   0x45B7

    #else
        #error "Unsupported PLL1 clock frequency (PLL_1_CLOCK)"
    #endif

#else

    #error "Unsupported oscillator frequency (EXTAL)"

#endif

    /* Other code here */
    return;

} /* MCU_SetSysClock */


/**
********************************************************************************
*
*  Function:    MCU_initCache
*  Description: Cache initialization (execute once at startup)
*
********************************************************************************
*/
static void MCU_InitCache(void)
{

}

Now, the first function is correctly highlighted:

While the second function is not:

Interestingly, removing the first #if (#if( PLL_0_CLOCK == 200000 )) fixes the problem; removing (only) the second one does not.

0 Likes

#11

There have been some improvements to the C family of syntaxes since build 3111. You can follow the instructions at https://github.com/sublimehq/Packages to try them. If you still see problems, please can you log an issue with the test case at https://github.com/sublimehq/Packages/issues - it is much easier to manage that way. Thanks! :slight_smile:

0 Likes

#12

Thank you: I just tried with the new packages, and the problem is still there. Therefore, I opened an issue in here.

0 Likes

#13

I just committed the fix for the issue you found. Thanks for pointing it out!

1 Like

#14

WOW! Thank you very much.
I can confirm that the fix is working.

0 Likes