Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding colors to dynamically added tokens #1220

Closed
reddys11 opened this issue Dec 4, 2018 · 4 comments
Closed

adding colors to dynamically added tokens #1220

reddys11 opened this issue Dec 4, 2018 · 4 comments
Labels
info-needed Issue requires more information from poster

Comments

@reddys11
Copy link

reddys11 commented Dec 4, 2018

for the first time all the tokens are getting color when the editor is loaded but when the user added new tokens dynamically then color is not applying to the recently created tokens,how can i update the tokens. can anyone help on this issue.

@alexdima
Copy link
Member

alexdima commented Dec 5, 2018

@reddys11 I am not sure what you mean. Can you add some code sample showing the problem? A screenshot might also help.

@alexdima alexdima added the info-needed Issue requires more information from poster label Dec 5, 2018
@reddys11
Copy link
Author

reddys11 commented Dec 10, 2018

This my code for getting colors..

 monaco.languages.setMonarchTokensProvider('RuleIT', {
                        ignoreCase: true,
                        ApplicationConstants: APPlConstants,
                        StateVariables: StateVariables,
                        InputVariables: IPVariables,
                        RuleVariables: RuleVariables,
                        Rules: rulesList,
                        ConditionBlocks: ['IF ALL THIS IS TRUE', 'IF ANY OF THIS IS TRUE', 'IF NONE OF THIS IS TRUE', 'THEN', 'OTHERWISE', 'ALL THIS IS TRUE', 'NONE OF THIS IS TRUE', 'ANY OF THIS IS TRUE'],
                        tokenizer: {
                            root: [
                                [/[A-Za-z0-9_$][\w$ ()-]*\b/, {
                                    cases: {
                                        '@ApplicationConstants': 'ApplicationConstants',
                                        '@StateVariables': 'StateVariables',
                                        '@InputVariables': 'InputVariables',
                                        '@ConditionBlocks': 'ConditionBlocks',
                                        '@RuleVariables': 'RuleVariables',
                                        '@Rules': 'Rules'
                                    }
                                }],

                                [/^\s*\/.*/, 'comment']
                            ]
                        }
                    });
                monaco.editor.defineTheme('RuleTheme', {
                        base: 'vs',
                        inherit: false,
                        rules: [{
                                token: 'ApplicationConstants',
                                foreground: '6680cc',
                                fontStyle: 'bold'
                            },
                            {
                                token: 'StateVariables',
                                foreground: '0000FF',
                                fontStyle: 'bold italic'
                            },
                            {
                                token: 'InputVariables',
                                foreground: '0000FF',
                                fontStyle: 'bold'
                            },
                            {
                                token: 'RuleVariables',
                                foreground: '0000FF'
                            },
                            {
                                token: 'ConditionBlocks',
                                foreground: '0079AD',
                                fontStyle: 'bold'
                            },
                            {
                                token: 'Rules',
                                foreground: 'C80000',
                                fontStyle: ''
                            },
                            {
                                token: 'comment',
                                foreground: '006100',
                                fontStyle: 'bold'
                            }
                        ]
                    });

when i load the editor instance i am getting colors for the variables by the above code. but when i tried try to create new variables and pushing it to the same array ,i am unable to get color for that variable.

@reddys11
Copy link
Author

color_issue

i am creating new variables and pushing to the already existing array,but i am not color to the created variable, the remaing elements(variables) which are present in the array are getting colors.

@alexdima
Copy link
Member

alexdima commented Jan 9, 2019

"and pushing to the already existing array"

Are you modifying the language definition data structure after you have called monaco.languages.setMonarchTokensProvider? i.e.

var foo = { ... };
monaco.languages.setMonarchTokensProvider(..., foo);
foo.bar.push(`baz`);

you should set the language grammar again if you are modifying it:

var foo = { ... };
monaco.languages.setMonarchTokensProvider(..., foo);
foo.bar.push(`baz`);
monaco.languages.setMonarchTokensProvider(..., foo);

@vscodebot vscodebot bot locked and limited conversation to collaborators Jan 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

2 participants