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

Add mongo to supported languages #1009

Closed
wants to merge 2 commits into from

Conversation

aymericbouzy
Copy link

@aymericbouzy aymericbouzy commented Oct 28, 2019

  • Run tests
  • Update the CHANGELOG.md with a summary of your changes

The Mongo Language has JS Syntax but is not formatted by Prettier. Changing language mode to "JS" for .mongo files works for formatting, but then the command to run the query against the DB is not available. It would make working with MongoDB inside of VS Code much easier !

@aymericbouzy
Copy link
Author

TSX test fails 😞 it seems unrelated : can someone help me?

    ✓ it formats JavaScript (789ms)
spec.js:83
formatTest/ugly.ts: 884.210ms
    ✓ it formats TypeScript (1186ms)
spec.js:83
formatTest/ugly.css: 393.751ms
    ✓ it formats CSS (613ms)
spec.js:83
formatTest/ugly.json: 237.554ms
    ✓ it formats JSON (622ms)
spec.js:83
formatTest/package.json: 83.589ms
    ✓ it formats JSON (158ms)
spec.js:83
formatTest/ugly.html: 198.389ms
    ✓ it formats HTML (952ms)
spec.js:83
    1) it formats TSX
spec.js:88
formatTest/ugly.scss: 165.068ms
    ✓ it formats SCSS (217ms)
spec.js:83
  Test configurations
spec.js:54
rcfile/test.js: 110.270ms
    ✓ it uses config from .prettierrc file  (217ms)
spec.js:83
jsconfigfile/test.js: 121.860ms
    ✓ it uses config from prettier.config.js file  (248ms)
spec.js:83
jsfile/test.js: 127.200ms
    ✓ it uses config from .prettierrc.js file  (245ms)
spec.js:83
  Test eslint
spec.js:54
withEslint.js: 2408.510ms
    ✓ it formats with prettier-eslint (2514ms)
spec.js:83
  Test ignore
spec.js:54
fileToIgnore.js: 78.310ms
    ✓ it does not format file (170ms)
spec.js:83
ignoreMe2/index.js: 56.426ms
    ✓ it does not format subfolder/* (324ms)
spec.js:83
ignoreMe/subdir/index.js: 61.368ms
    ✓ it does not format sub-subfolder (176ms)
spec.js:83
  Test plugins
spec.js:54
index.php: 168.616ms
    ✓ it formats with plugins (356ms)
spec.js:83
  Test tslint
spec.js:54
withTslint.ts: 3174.600ms
    ✓ it formats with prettier-tslint (3362ms)
spec.js:83
  16 passing (22s)
base.js:324
  1 failing
base.js:337
  1) Test format Document
       it formats TSX:
     Error: Timeout of 10000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/Users/aymericbouzy/Dev/prettier-vscode/out/test/suite/config.test.js)
  

base.js:261

@aymericbouzy
Copy link
Author

I have tested running the extension together with Azure Cosmos DB and it works 🎉 my .mongo file is formated, and I can execute my mongo command.

@aymericbouzy aymericbouzy marked this pull request as ready for review October 28, 2019 15:20
@aymericbouzy
Copy link
Author

Can someone indicate me if I need to add a test for .mongo files? I assume I need to create an "ugly" file inside of test-fixtures/project/formatTest? Is that the way to go?

@ntotten
Copy link
Member

ntotten commented Oct 28, 2019

This would be a change for the Prettier library itself rather than the VS Code extension for prettier. Please open an issue at https://github.com/prettier/prettier.

Specifically, you would need to add a new supported language to prettier that tells prettier that a mongodb file should use the json parser.

@ntotten ntotten closed this Oct 28, 2019
@aymericbouzy
Copy link
Author

aymericbouzy commented Oct 31, 2019

I'm a bit lost at what would need to be changed in the prettier codebase, and I'm not sure why you are mentioning JSON. A mongo file looks like this :

db.users.find({ someField: { $exists: true } });

I have found one issue in prettier mentioning .mongo files, and I understand @vjeux wants to support mongo queries, since they use the javascript language. I think mongo files are not a different language that prettier needs to support, but simply a different file extension that needs to be recognised as containing valid javascript. Correct me if I'm wrong, but it seems to me this is the responsibility of the vs code extension to define a formatter on .mongo files ?

prettier/prettier#1574

@aymericbouzy
Copy link
Author

I did open an issue as you suggested 👍

@aymericbouzy
Copy link
Author

My PR to the prettier codebase has been merged prettier/prettier#6848

Would you consider reopening this PR? @ntotten

@thorn0
Copy link
Member

thorn0 commented Nov 6, 2019

I guess rangeSupportedLanguages means it's a hardcoded list of languages for which formatting of ranges is supported. Why doesn't Prettier itself provide this information I wonder? Anyways, this change doesn't seem to be essential for your use case @aymericbouzy.

@aymericbouzy
Copy link
Author

You are right @thorn0 the change in the prettier codebase is enough. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants