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

Parse error on "as user" keywords (User Mode for Database Operations) #738

Closed
pozil opened this issue Dec 28, 2022 · 13 comments
Closed

Parse error on "as user" keywords (User Mode for Database Operations) #738

pozil opened this issue Dec 28, 2022 · 13 comments

Comments

@pozil
Copy link

pozil commented Dec 28, 2022

Hi @dangmai, I guess that this issue will be closed with the Jorje update that you're working on but I felt that I should report it anyways for visibility.

Over the last couple of release we've introduced User Mode for Database Operations. This adds new as user Apex keywords.

The current version of the parser embedded in the Apex Prettier plugin is failing to parse the following valid Apex code:

insert as user newContact;

This produces an error like this:

Error:  Unexpected token 'as'..
Error:      at Object.parse (/home/runner/work/visualforce-to-lwc/visualforce-to-lwc/node_modules/prettier-plugin-apex/dist/src/parser.js:467:19)
Error:      at Object.parse (/home/runner/work/visualforce-to-lwc/visualforce-to-lwc/node_modules/prettier/index.js:7331:23)
Error:      at coreFormat (/home/runner/work/visualforce-to-lwc/visualforce-to-lwc/node_modules/prettier/index.js:8645:18)
Error:      at formatWithCursor2 (/home/runner/work/visualforce-to-lwc/visualforce-to-lwc/node_modules/prettier/index.js:8837:18)
Error:      at Object.formatWithCursor (/home/runner/work/visualforce-to-lwc/visualforce-to-lwc/node_modules/prettier/index.js:37832:12)
Error:      at format (/home/runner/work/visualforce-to-lwc/visualforce-to-lwc/node_modules/prettier/cli.js:[14](https://github.com/trailheadapps/visualforce-to-lwc/actions/runs/3795057895/jobs/6453778921#step:6:15)789:24)
Error:      at formatFiles2 (/home/runner/work/visualforce-to-lwc/visualforce-to-lwc/node_modules/prettier/cli.js:14903:22)
Error:      at async main (/home/runner/work/visualforce-to-lwc/visualforce-to-lwc/node_modules/prettier/cli.js:[15](https://github.com/trailheadapps/visualforce-to-lwc/actions/runs/3795057895/jobs/6453778921#step:6:16)128:5)
Error:      at async Object.run (/home/runner/work/visualforce-to-lwc/visualforce-to-lwc/node_modules/prettier/cli.js:15075:5)
Error:  force-app/main/default/classes/CreateMixedRecordsApexControllerLwc.cls: Error: Unexpected token 'as'..

Thanks again for all of the hard work you're putting on the plugin.

@dangmai
Copy link
Owner

dangmai commented Dec 28, 2022

Thank you for opening this issue. I've been checking to see if jorje supports this new syntax for a while, but haven't seen any update with regards to it. It looks like the LSP does support this syntax now though, I'll check to see how it's being done in the LSP.

@dangmai
Copy link
Owner

dangmai commented Dec 28, 2022

The error is coming straight from jorje, so my hunch is that there might be some flag I need to pass in so that this syntax can be parsed. Do you have any contact in the team that owns jorje or LSP that I can talk to in order to understand how to implement this properly?

FYI this is how Apex code is being parsed by apex-ast-serializer: https://github.com/dangmai/apex-ast-serializer/blob/master/src/main/java/net/dangmai/serializer/Apex.java#L65

Thanks!

@pozil
Copy link
Author

pozil commented Dec 29, 2022

Thanks for investigating. I'll try to find the right people and send them your way.

@drd0013
Copy link

drd0013 commented Jan 15, 2023

+1 to this issue

@dangmai dangmai pinned this issue Jan 17, 2023
@pozil
Copy link
Author

pozil commented Jan 25, 2023

Hi @dangmai, it took a bit of time to chase the right owner for this and I had to send a friendly reminder but this is now tracked and the team should update the JAR soon. I'll keep you posted if I hear anything.

@dangmai
Copy link
Owner

dangmai commented Jan 25, 2023

Thank you so much for tracking that down @pozil! I will add support for this syntax and release a new version as soon as the new JAR is out 👍

@nabondance
Copy link

Hello, we have the same issue with as system

@nwcm
Copy link
Contributor

nwcm commented Mar 10, 2023

Also having this issue

@pozil
Copy link
Author

pozil commented Mar 14, 2023

Hi all, this is still on the backlog of our tooling team. I'll send them a reminder but it looks like they are swamped with requests.

@dangmai
Copy link
Owner

dangmai commented Apr 23, 2023

Support for as user and as system keywords in DML operations has been added and released in Prettier Apex 1.13.0.

@pozil
Copy link
Author

pozil commented Apr 24, 2023

Thanks @dangmai. I'm surprised that I didn't get the update that jorge had been updated but I'm glad that you saw it first :)

@AnanyaJha
Copy link

Thank you for the quick update @dangmai ! To answer your question Philippe, we haven't released the new version of the Apex Extension with the updated LSP jar yet, but it's been merged in. Should be going out this week and we'll update you all officially then :)

@tehnrd
Copy link

tehnrd commented May 6, 2023

Very important tip. After updating, make sure to shut down and restart VS Code completely. I didn't do this at only did npm i then formatted code and it changed upsert as user setting; to upsert setting; Restart fixed this and it isn't removing the as user part any more.

IlyaMatsuev added a commit to IlyaMatsuev/prettier-plugin-apex that referenced this issue Jul 2, 2023
* Update dependency @types/node to v18.11.16

* Update dependency eslint to v8.30.0

* Update dependency @types/node to v18.11.17

* Update dependency wait-on to v7 (dangmai#730)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update typescript-eslint monorepo to v5.47.0

* Update dependency @types/node to v18.11.18

* Update typescript-eslint monorepo to v5.47.1

* Update dependency @types/jest to v29.2.5

* Update dependency eslint to v8.31.0

* Update dependency eslint-config-prettier to v8.6.0

* Update typescript-eslint monorepo to v5.48.0

* Update dependency husky to v8.0.3

* Update actions/setup-node action to v3.6.0

* Update dependency prettier to v2.8.2

* Bump json5 from 1.0.1 to 1.0.2 (dangmai#745)

Bumps [json5](https://github.com/json5/json5) from 1.0.1 to 1.0.2.
- [Release notes](https://github.com/json5/json5/releases)
- [Changelog](https://github.com/json5/json5/blob/main/CHANGELOG.md)
- [Commits](json5/json5@v1.0.1...v1.0.2)

---
updated-dependencies:
- dependency-name: json5
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Update typescript-eslint monorepo to v5.48.1

* Update dependency ts-jest to v29.0.4

* Update dependency eslint-plugin-import to v2.27.4

* Update dependency ts-jest to v29.0.5

* Update dependency prettier to v2.8.3

* Update dependency rimraf to v4 (dangmai#751)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update dependency rimraf to v4.0.5

* Updated jorje (dangmai#735)

Co-authored-by: dangmai <dangmai@users.noreply.github.com>

* Update dependency eslint to v8.32.0

* Update dependency rimraf to v4.0.7

* Update typescript-eslint monorepo to v5.48.2

* Update dependency eslint-plugin-import to v2.27.5

* Update dependency rimraf to v4.1.0

* Update dependency rimraf to v4.1.1

* Update dependency @types/jest to v29.2.6

* Update typescript-eslint monorepo to v5.49.0

* Update dependency rimraf to v4.1.2

* Update dependency jest to v29.4.0

* Update dependency @types/jest to v29.4.0

* Update dependency jest to v29.4.1

* Update dependency eslint to v8.33.0

* Update dependency typescript to v4.9.5

* Update typescript-eslint monorepo to v5.50.0

* Updated jorje (dangmai#771)

Co-authored-by: dangmai <dangmai@users.noreply.github.com>

* Update dependency @types/node to v18.11.19

* Update typescript-eslint monorepo to v5.51.0

* Updated jorje (dangmai#774)

Co-authored-by: dangmai <dangmai@users.noreply.github.com>

* Update dependency @types/node to v18.13.0

* Update dependency jest to v29.4.2

* Update dependency prettier to v2.8.4

* [chore] enable renovate lockFileMaintenance

* [chore] fix renovate config

* Lock file maintenance

* Update dependency eslint to v8.34.0

* Lock file maintenance

* Updated jorje (dangmai#783)

Co-authored-by: dangmai <dangmai@users.noreply.github.com>

* Update typescript-eslint monorepo to v5.52.0

* Update dependency jest to v29.4.3

* Update dependency @types/node to v18.14.0

* Lock file maintenance

* Lock file maintenance

* Update typescript-eslint monorepo to v5.53.0

* Update dependency @types/node to v18.14.1

* Update dependency eslint to v8.35.0

* Update dependency @types/node to v18.14.2

* Lock file maintenance

* Update typescript-eslint monorepo to v5.54.0

* Updated jorje

* Update dependency rimraf to v4.1.3

* Update dependency @types/node to v18.14.4

* Update dependency rimraf to v4.2.0

* Update dependency @types/node to v18.14.5

* Update dependency @types/node to v18.14.6

* Update dependency rimraf to v4.3.0

* Lock file maintenance

* Update dependency eslint-config-prettier to v8.7.0

* Update dependency rimraf to v4.3.1

* Update typescript-eslint monorepo to v5.54.1

* Update dependency jest to v29.5.0

* Update dependency rimraf to v4.4.0

* Update dependency @types/node to v18.15.0

* Update dependency eslint to v8.36.0

* Lock file maintenance

* Update dependency @types/node to v18.15.1

* Update dependency @types/jest to v29.4.1

* Update dependency @types/node to v18.15.2

* Update typescript-eslint monorepo to v5.55.0

* Update dependency @types/node to v18.15.3

* Update peter-evans/create-pull-request action to v4.2.4

* Update dependency @types/jest to v29.4.2

* Update dependency @types/jest to v29.4.4

* Update dependency typescript to v5

* Update dependency @types/jest to v29.5.0

* Updated jorje

* Lock file maintenance

* Update dependency prettier to v2.8.5

* Update typescript-eslint monorepo to v5.56.0

* Update dependency eslint-config-prettier to v8.8.0

* Update dependency @types/node to v18.15.5

* Update dependency prettier to v2.8.6

* Update dependency rimraf to v4.4.1

* Update dependency @types/node to v18.15.6

* Update dependency @types/node to v18.15.8

* Update dependency prettier to v2.8.7

* Update dependency @types/node to v18.15.9

* Update dependency @types/node to v18.15.10

* Lock file maintenance

* Update typescript-eslint monorepo to v5.57.0

* Update dependency @types/node to v18.15.11

* Update dependency eslint to v8.37.0

* Update dependency typescript to v5.0.3

* Update dependency ts-jest to v29.1.0

* Lock file maintenance

* Update typescript-eslint monorepo to v5.57.1

* Update dependency axios to v1.3.5

* Update dependency typescript to v5.0.4

* Update dependency eslint to v8.38.0

* Update typescript-eslint monorepo to v5.58.0

* Lock file maintenance

* Update peter-evans/create-pull-request action to v5

* Updated jorje

* Update dependency rimraf to v5

* Lock file maintenance

* Update typescript-eslint monorepo to v5.59.0

* Update dependency @types/jest to v29.5.1

* Update dependency axios to v1.3.6

* Update dependency @types/node to v18.15.12

* Update dependency @types/node to v18.15.13

* Update dependency eslint to v8.39.0

* Update dependency @types/node to v18.16.0

* Update dependency prettier to v2.8.8

* Updated jorje

* chore - remove husky and yarnhook

* Fix dangmai#738 - Add support for User Mode in Database Operations

* chore - remove husky files

* Update JS-DevTools/npm-publish action to v2

* chore - remove workaround for npm-publish action

* Finalize CHANGELOG for 1.13.0

* 1.13.0

* Lock file maintenance

* Update typescript-eslint monorepo to v5.59.1

* Update dependency @types/node to v18.16.1

* Update dependency @types/node to v18.16.2

* Update dependency yargs to v17.7.2

* Update dependency axios to v1.4.0

* Update dependency @types/node to v18.16.3

* Updated jorje

* Lock file maintenance

* Update typescript-eslint monorepo to v5.59.2

* Update peter-evans/create-pull-request action to v5.0.1

* Update dependency @types/node to v18.16.4

* Update dependency @types/node to v18.16.5

* Update dependency eslint to v8.40.0

* Init commit to get Prettier to run

* Switch peerDependency to all versions of Prettier ^3.0.0

* Switch parser to async

* Fix parser tests

* Adopt runSpec to new Prettier async API

* Swap out usage of Concat type

* Add --experimental-vm-modules so Jest can use ESM

* Make sure tests can run on Windows

* Stop running tests on NodeJS 14

* Remove all usage of concat

* Fix various ESLint issues

* Cleaning up ESLint deps

* Temporarily add synckit as dev dep

Otherwise eslint-plugin-prettier complains about missing module

* Temporarily ignore ESLint rule ban-ts-comment

* Fix plugin entry point for debug-check script

* Run tests without compiling first

* Create standalone bundle

* Build standalone package directly into `dist` directory

* Remove output dir from gitignore

* Use fetch API instead of axios

* Fix linting issue

* Increase timeout for synchronous parser tests

* Debug in VSCode

* Upgrade prettier to latest alpha version

* Roll back dependency prettier to ^3.0.0-alpha

* Add docs for Prettier v3 upgrade

* Switch to node16 base for tsconfig

* Upgrade to prettier 3.0.0-alpha.11

* Update dependency @rollup/plugin-commonjs to v23.0.7

* Update dependency eslint-plugin-prettier to v5.0.0-alpha.1

* Update dependency @rollup/plugin-node-resolve to v15.0.2

* Remove direct dep on synckit

* Update dependency rollup to v3.21.5

* Update dependency @babel/preset-env to v7.21.5

* Update dependency rollup-plugin-polyfill-node to v0.12.0

* Update dependency @rollup/plugin-terser to v0.4.1

* Update dependency @rollup/plugin-json to v6

* Update dependency @rollup/plugin-commonjs to v24

* Update dependency @rollup/plugin-typescript to v11

* Replace usage of deprecated getValue method

* Fix code format

* Remove usage of non null assertion

* Update dependency @types/node to v18.16.6

* Update typescript-eslint monorepo to v5.59.5

* Update dependency rollup to v3.21.6

* Update dependency @types/node to v18.16.7

* Update dependency @types/node to v18.16.8

* Update dependency @tsconfig/node16 to v1.0.4

* Update dependency @rollup/plugin-commonjs to v25

* Update dependency @rollup/plugin-typescript to v11.1.1

* Update dependency @types/node to v18.16.9

* Update dependency rollup to v3.21.7

* Add helper script to run tests in standalone mode

* [chore] set up asdf tool versions and bump NodeJS dependency

* [chore] include bin folder when running prettier

* Replace yargs with NodeJS built-in parseArgs

* Update dependency cross-fetch to v3.1.6

* Add vite dev dependency

* Init vite config

* Switch from rollup to vite

* change standalone file name in package.json

* helper scripts for vite

* make sure vite doesn't empty dist dir

* Lock file maintenance

* Update dependency vite to v4.3.6

* Update typescript-eslint monorepo to v5.59.6

* Update dependency vite to v4.3.7

* Update dependency rimraf to v5.0.1

* Update dependency vite to v4.3.8

* Update dependency eslint to v8.41.0

* Updated jorje

* Lock file maintenance

* Update typescript-eslint monorepo to v5.59.7

* Update dependency vite to v4.3.9

* Lock file maintenance

* Update typescript-eslint monorepo to v5.59.8

* Update dependency @types/jest to v29.5.2

* Update dependency typescript to v5.1.3

* Update dependency eslint to v8.42.0

* Lock file maintenance

* Update typescript-eslint monorepo to v5.59.9

* Updated jorje

* Lock file maintenance

* Update typescript-eslint monorepo to v5.59.11

* Update peter-evans/create-pull-request action to v5.0.2

* Updated jorje

* Update dependency eslint to v8.43.0

* Lock file maintenance

* Update typescript-eslint monorepo to v5.60.0

* chore - latest Prettier alpha

* Lock file maintenance

* Update typescript-eslint monorepo to v5.60.1

* Update dependency @tsconfig/node16 to v16

* Update dependency typescript to v5.1.5

* Update dependency typescript to v5.1.6

* Updated jorje

* Update dependency ts-jest to v29.1.1

* Updated jorje

* Update dependency eslint to v8.44.0

* Update dependency cross-fetch to v3.1.7

* Add husky to dev dependencies

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Dang Mai <contact@dangmai.net>
Co-authored-by: dangmai <dangmai@users.noreply.github.com>
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

No branches or pull requests

7 participants