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

More friendly error handling of invalid .tmTheme and .tmLanguage inputs? #100

Open
JacksonKearl opened this issue Jan 8, 2018 · 2 comments
Assignees
Labels
feature-request Request for new features or functionality
Milestone

Comments

@JacksonKearl
Copy link

When creating a color theme or language, you are first asked to provide a link to the .tm* file you'd like to base it on.

When creating a language, this link is not validated until after the user has been asked for all other data, at which point the generator logs an error message and leaves the created directory in a weird state if it cannot correctly parse the link provided (in these cases I demonstrate via passing a GitHub.com link as opposed to raw.github.com, as it should be):

? What type of extension do you want to create? New Language Support
Enter the URL (http, https) or the file path of the tmLanguage grammar or press ENTER to start with a new grammar.
? URL or file to import, or none for new: https://github.com/ammubhave/bluespec-sublime/blob/master/Bluespec.tmLanguage
? What's the name of your extension? dfadf
? What's the identifier of your extension? asdfasdfasdf
? What's the description of your extension? asdfsadfsdgsdfgsdfgsdfg
? What's your publisher name (more info: https://code.visualstudio.com/docs/tools/vscecli#_publishing-extensions)? jke
arl
Enter the id of the language. The id is an identifier and is single, lower-case name such as 'php', 'javascript'
? Language id: dsfdsgdfsdsafasd
Enter the name of the language. The name will be shown in the VS Code editor mode selector.
? Language name: asdfasfagsdfgadsfasdvsdagad
Enter the file extensions of the language. Use commas to separate multiple entries (e.g. .ruby, .rb)
? File extensions: .dfasdf
Enter the root scope name of the grammar (e.g. source.ruby)
? Scope names: dfasdf.fasdfas
   create asdfasdfasdf/syntaxes/dsfdsgdfsdsafasd.tmLanguage.json
   create asdfasdfasdf/.vscode/launch.json
   create asdfasdfasdf/package.json
   create asdfasdfasdf/README.md
   create asdfasdfasdf/CHANGELOG.md
   create asdfasdfasdf/vsc-extension-quickstart.md
   create asdfasdfasdf/language-configuration.json
   create asdfasdfasdf/.vscodeignore
   create asdfasdfasdf/.gitignore

Your extension asdfasdfasdf has been created!

To start editing with Visual Studio Code, use the following commands:

     cd asdfasdfasdf
     code .

Open vsc-extension-quickstart.md inside the new extension for further instructions
on how to modify, test and publish your extension.

For more information, also visit http://code.visualstudio.com and follow us @code.


Error: Promise rejected with value: 'Language definition file does not contain \'DOCTYPE plist\'. Make sure the file content is really plist-XML.'
    at /usr/local/lib/node_modules/yo/node_modules/loud-rejection/index.js:27:12
    at Array.forEach (<anonymous>)
    at EventEmitter.<anonymous> (/usr/local/lib/node_modules/yo/node_modules/loud-rejection/index.js:23:24)
    at emitTwo (events.js:126:13)
    at EventEmitter.emit (events.js:214:7)
    at emit (/usr/local/lib/node_modules/yo/node_modules/signal-exit/index.js:77:11)
    at processEmit [as emit] (/usr/local/lib/node_modules/yo/node_modules/signal-exit/index.js:150:5)

Similarly, when making a color theme, it logs an error immediately after providing an invalid link, but lets the user continue entering metadata, and when it finishes also creates a directory left in a weird state:

? What type of extension do you want to create? New Color Theme
? Do you want to import or convert an existing TextMate color theme? Import an existing theme but keep it as tmTheme file.
Enter the location (URL (http, https) or file name) of the tmTheme file, e.g., http://www.monokai.nl/blog/wp-content/asdev/Monokai.tmTheme.
? URL or file name to import: https://github.com/sethlopezme/InspiredGitHub.tmtheme/blob/master/InspiredGitHub.tmTheme
TypeError: Cannot read property 'settings' of null
    at migrate (/usr/local/lib/node_modules/generator-code/generators/app/themeConverter.js:117:30)
    at processContent (/usr/local/lib/node_modules/generator-code/generators/app/themeConverter.js:74:36)
    at Request._callback (/usr/local/lib/node_modules/generator-code/generators/app/themeConverter.js:38:21)
    at Request.self.callback (/usr/local/lib/node_modules/generator-code/node_modules/request/request.js:186:22)
    at emitTwo (events.js:126:13)
    at Request.emit (events.js:214:7)
    at Request.<anonymous> (/usr/local/lib/node_modules/generator-code/node_modules/request/request.js:1163:10)
    at emitOne (events.js:116:13)
    at Request.emit (events.js:211:7)
    at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/generator-code/node_modules/request/request.js:1085:12)
? What's the name of your extension? adf
? What's the identifier of your extension? asdfaf
? What's the description of your extension? adfafa
...
...

I think the script should validate these input as soon as they are entered (as it does with publisher name), to ensure the user knows what the issue is when providing an invalid file, and isn't left with a directory in an unexpected state. I am willing to work on a PR for this if the maintainers agree?

@alefragnani
Copy link
Contributor

I tried to use the convert process described in the API Documentation, but even using the sample provided in the screenshot, this error occurs.

Otherwise, if you use the GitHub RAW link instead, no error occurs, but the file is not converted from .tmLanguage (XML format) to .tmLanguage.json (JSON format) as described. It is generated as .tmLanguage (XML format).

@alefragnani
Copy link
Contributor

Looking closer at the generator source code, it appears that there is no converter (from .tmLanguage to .tmLanguage.json) after all. I think I misinterpreted the documentation, sorry

https://github.com/Microsoft/vscode-generator-code/blob/30b4121da07f1c189340a0d1cd1367d07b0e9850/generators/app/index.js#L619

    // Write Language Extension
    _writingLanguage() {
        let context = this.extensionConfig;
        if (!context.languageContent) {
            context.languageFileName = sanitize(context.languageId + '.tmLanguage.json');

            this.fs.copyTpl(this.sourceRoot() + '/syntaxes/new.tmLanguage.json', context.name + '/syntaxes/' + context.languageFileName, context);
        } else {
            this.fs.copyTpl(this.sourceRoot() + '/syntaxes/language.tmLanguage', context.name + '/syntaxes/' + sanitize(context.languageFileName), context);
        }

I was expecting to convert from XML to JSON format, just to "update" my language extension.

Maybe a feature request 😁 .

Thank you

@aeschli aeschli added the feature-request Request for new features or functionality label Oct 14, 2019
@aeschli aeschli added this to the Backlog milestone Oct 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

3 participants