-
-
Notifications
You must be signed in to change notification settings - Fork 52
feat: support "Format on Paste" #161
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
Merged
idahogurl
merged 2 commits into
master
from
139-extension-inserts-unwanted-semicolon-and
Apr 22, 2023
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,16 @@ | ||
| { | ||
| // Use IntelliSense to learn about possible attributes. | ||
| // Hover to view descriptions of existing attributes. | ||
| // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
| "version": "0.2.0", | ||
| "configurations": [{ | ||
| "name": "Run Extension", | ||
| "type": "extensionHost", | ||
| "request": "launch", | ||
| "runtimeExecutable": "${execPath}", | ||
| "args": ["--extensionDevelopmentPath=${workspaceFolder}"] | ||
| }] | ||
| } | ||
| // Use IntelliSense to learn about possible attributes. | ||
| // Hover to view descriptions of existing attributes. | ||
| // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
| "version": "0.2.0", | ||
| "configurations": [ | ||
| { | ||
| "name": "Run Extension", | ||
| "type": "extensionHost", | ||
| "request": "launch", | ||
| "runtimeExecutable": "${execPath}", | ||
| "args": ["--extensionDevelopmentPath=${workspaceFolder}"], | ||
| "outFiles": ["${workspaceFolder}/dist/**/*.js"] | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ | |
| */ | ||
|
|
||
| import { | ||
| languages, window, TextEdit, workspace, | ||
| languages, window, TextEdit, Range, workspace, | ||
| } from 'vscode'; | ||
|
|
||
| import format from './formatter'; | ||
|
|
@@ -14,7 +14,7 @@ const path = require('path'); | |
|
|
||
| let outputChannel; | ||
|
|
||
| async function formatter(document, range) { | ||
| async function formatter(document) { | ||
| const documentPath = path.dirname(document.fileName); | ||
| const workspaceDir = workspace?.workspaceFolders.find((w) => documentPath.startsWith(w.uri.path)) | ||
| ?.uri.path; | ||
|
|
@@ -27,6 +27,10 @@ async function formatter(document, range) { | |
| console.log('File ignored.'); | ||
| outputChannel.appendLine('File ignored. Matches entry in .eslintignore or .prettierignore'); | ||
| } else { | ||
| const startLine = document.lineAt(0); | ||
| const endLine = document.lineAt(document.lineCount - 1); | ||
| const range = new Range(startLine.range.start, endLine.range.end); | ||
|
|
||
| const text = document.getText(range); | ||
| const extensionConfig = workspace?.getConfiguration('vs-code-prettier-eslint'); | ||
| const formatted = await format({ | ||
|
|
@@ -42,8 +46,8 @@ async function formatter(document, range) { | |
| } | ||
|
|
||
| const formattingProvider = { | ||
| provideDocumentRangeFormattingEdits(document, range) { | ||
| return formatter(document, range); | ||
| provideDocumentRangeFormattingEdits(document) { | ||
| return formatter(document); | ||
|
Comment on lines
-45
to
+50
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ignore provided range |
||
| }, | ||
| }; | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -625,6 +625,18 @@ | |
| resolved "https://registry.yarnpkg.com/@esbuild/win32-x64/-/win32-x64-0.16.14.tgz#90558dcb279989d92a42e5be4dfb884b2399361f" | ||
| integrity sha512-ED1UpWcM6lAbalbbQ9TrGqJh4Y9TaASUvu8bI/0mgJcxhSByJ6rbpgqRhxYMaQ682WfA71nxUreaTO7L275zrw== | ||
|
|
||
| "@eslint-community/eslint-utils@^4.2.0": | ||
| version "4.4.0" | ||
| resolved "https://registry.yarnpkg.com/@eslint-community/eslint-utils/-/eslint-utils-4.4.0.tgz#a23514e8fb9af1269d5f7788aa556798d61c6b59" | ||
| integrity sha512-1/sA4dwrzBAyeUoQ6oxahHKmrZvsnLCg4RfxW3ZFGGmQkSNQPFNLV9CUEFQP1x9EYXHTo5p6xdhZM1Ne9p/AfA== | ||
| dependencies: | ||
| eslint-visitor-keys "^3.3.0" | ||
|
|
||
| "@eslint-community/regexpp@^4.4.0": | ||
| version "4.5.0" | ||
| resolved "https://registry.yarnpkg.com/@eslint-community/regexpp/-/regexpp-4.5.0.tgz#f6f729b02feee2c749f57e334b7a1b5f40a81724" | ||
| integrity sha512-vITaYzIcNmjn5tF5uxcZ/ft7/RXGrMUIS9HalWckEOF6ESiwXKoMzAQf2UW0aVd6rnOeExTJVd5hmWXucBKGXQ== | ||
|
|
||
| "@eslint/eslintrc@^1.2.2": | ||
| version "1.2.2" | ||
| resolved "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.2.2.tgz" | ||
|
|
@@ -640,21 +652,26 @@ | |
| minimatch "^3.0.4" | ||
| strip-json-comments "^3.1.1" | ||
|
|
||
| "@eslint/eslintrc@^1.4.1": | ||
| version "1.4.1" | ||
| resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-1.4.1.tgz#af58772019a2d271b7e2d4c23ff4ddcba3ccfb3e" | ||
| integrity sha512-XXrH9Uarn0stsyldqDYq8r++mROmWRI1xKMXa640Bb//SY1+ECYX6VzT6Lcx5frD0V30XieqJ0oX9I2Xj5aoMA== | ||
| "@eslint/eslintrc@^2.0.2": | ||
| version "2.0.2" | ||
| resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-2.0.2.tgz#01575e38707add677cf73ca1589abba8da899a02" | ||
| integrity sha512-3W4f5tDUra+pA+FzgugqL2pRimUTDJWKr7BINqOpkZrC0uYI0NIc0/JFgBROCU07HR6GieA5m3/rsPIhDmCXTQ== | ||
| dependencies: | ||
| ajv "^6.12.4" | ||
| debug "^4.3.2" | ||
| espree "^9.4.0" | ||
| espree "^9.5.1" | ||
| globals "^13.19.0" | ||
| ignore "^5.2.0" | ||
| import-fresh "^3.2.1" | ||
| js-yaml "^4.1.0" | ||
| minimatch "^3.1.2" | ||
| strip-json-comments "^3.1.1" | ||
|
|
||
| "@eslint/[email protected]": | ||
| version "8.39.0" | ||
| resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.39.0.tgz#58b536bcc843f4cd1e02a7e6171da5c040f4d44b" | ||
| integrity sha512-kf9RB0Fg7NZfap83B3QOqOGg9QmD9yBudqQXzzOtn3i4y7ZUXe5ONeW34Gwi+TxhH4mvj72R1Zc300KUMa9Bng== | ||
|
|
||
| "@humanwhocodes/config-array@^0.11.8": | ||
| version "0.11.8" | ||
| resolved "https://registry.yarnpkg.com/@humanwhocodes/config-array/-/config-array-0.11.8.tgz#03595ac2075a4dc0f191cc2131de14fbd7d410b9" | ||
|
|
@@ -2618,6 +2635,14 @@ eslint-scope@^7.0.0, eslint-scope@^7.1.1: | |
| esrecurse "^4.3.0" | ||
| estraverse "^5.2.0" | ||
|
|
||
| eslint-scope@^7.2.0: | ||
| version "7.2.0" | ||
| resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-7.2.0.tgz#f21ebdafda02352f103634b96dd47d9f81ca117b" | ||
| integrity sha512-DYj5deGlHBfMt15J7rdtyKNq/Nqlv5KfU4iodrQ019XESsRnwXH9KAE0y3cwtUHDo2ob7CypAnCqefh6vioWRw== | ||
| dependencies: | ||
| esrecurse "^4.3.0" | ||
| estraverse "^5.2.0" | ||
|
|
||
| eslint-utils@^3.0.0: | ||
| version "3.0.0" | ||
| resolved "https://registry.npmjs.org/eslint-utils/-/eslint-utils-3.0.0.tgz" | ||
|
|
@@ -2635,12 +2660,20 @@ eslint-visitor-keys@^3.0.0, eslint-visitor-keys@^3.1.0, eslint-visitor-keys@^3.3 | |
| resolved "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.3.0.tgz" | ||
| integrity sha512-mQ+suqKJVyeuwGYHAdjMFqjCyfl8+Ldnxuyp3ldiMBFKkvytrXUZWaiPCEav8qDHKty44bD+qV1IP4T+w+xXRA== | ||
|
|
||
| eslint-visitor-keys@^3.4.0: | ||
| version "3.4.0" | ||
| resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-3.4.0.tgz#c7f0f956124ce677047ddbc192a68f999454dedc" | ||
| integrity sha512-HPpKPUBQcAsZOsHAFwTtIKcYlCje62XB7SEAcxjtmW6TD1WVpkS6i6/hOVtTZIl4zGj/mBqpFVGvaDneik+VoQ== | ||
|
|
||
| eslint@^8.31.0: | ||
| version "8.31.0" | ||
| resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.31.0.tgz#75028e77cbcff102a9feae1d718135931532d524" | ||
| integrity sha512-0tQQEVdmPZ1UtUKXjX7EMm9BlgJ08G90IhWh0PKDCb3ZLsgAOHI8fYSIzYVZej92zsgq+ft0FGsxhJ3xo2tbuA== | ||
| dependencies: | ||
| "@eslint/eslintrc" "^1.4.1" | ||
| version "8.39.0" | ||
| resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.39.0.tgz#7fd20a295ef92d43809e914b70c39fd5a23cf3f1" | ||
| integrity sha512-mwiok6cy7KTW7rBpo05k6+p4YVZByLNjAZ/ACB9DRCu4YDRwjXI01tWHp6KAUWelsBetTxKK/2sHB0vdS8Z2Og== | ||
| dependencies: | ||
| "@eslint-community/eslint-utils" "^4.2.0" | ||
| "@eslint-community/regexpp" "^4.4.0" | ||
| "@eslint/eslintrc" "^2.0.2" | ||
| "@eslint/js" "8.39.0" | ||
| "@humanwhocodes/config-array" "^0.11.8" | ||
| "@humanwhocodes/module-importer" "^1.0.1" | ||
| "@nodelib/fs.walk" "^1.2.8" | ||
|
|
@@ -2650,11 +2683,10 @@ eslint@^8.31.0: | |
| debug "^4.3.2" | ||
| doctrine "^3.0.0" | ||
| escape-string-regexp "^4.0.0" | ||
| eslint-scope "^7.1.1" | ||
| eslint-utils "^3.0.0" | ||
| eslint-visitor-keys "^3.3.0" | ||
| espree "^9.4.0" | ||
| esquery "^1.4.0" | ||
| eslint-scope "^7.2.0" | ||
| eslint-visitor-keys "^3.4.0" | ||
| espree "^9.5.1" | ||
| esquery "^1.4.2" | ||
| esutils "^2.0.2" | ||
| fast-deep-equal "^3.1.3" | ||
| file-entry-cache "^6.0.1" | ||
|
|
@@ -2675,7 +2707,6 @@ eslint@^8.31.0: | |
| minimatch "^3.1.2" | ||
| natural-compare "^1.4.0" | ||
| optionator "^0.9.1" | ||
| regexpp "^3.2.0" | ||
| strip-ansi "^6.0.1" | ||
| strip-json-comments "^3.1.0" | ||
| text-table "^0.2.0" | ||
|
|
@@ -2730,14 +2761,14 @@ espree@^9.0.0, espree@^9.3.1: | |
| acorn-jsx "^5.3.1" | ||
| eslint-visitor-keys "^3.3.0" | ||
|
|
||
| espree@^9.4.0: | ||
| version "9.4.0" | ||
| resolved "https://registry.yarnpkg.com/espree/-/espree-9.4.0.tgz#cd4bc3d6e9336c433265fc0aa016fc1aaf182f8a" | ||
| integrity sha512-DQmnRpLj7f6TgN/NYb0MTzJXL+vJF9h3pHy4JhCIs3zwcgez8xmGg3sXHcEO97BrmO2OSvCwMdfdlyl+E9KjOw== | ||
| espree@^9.5.1: | ||
| version "9.5.1" | ||
| resolved "https://registry.yarnpkg.com/espree/-/espree-9.5.1.tgz#4f26a4d5f18905bf4f2e0bd99002aab807e96dd4" | ||
| integrity sha512-5yxtHSZXRSW5pvv3hAlXM5+/Oswi1AUFqBmbibKb5s6bp3rGIDkyXU6xCoyuuLhijr4SFwPrXRoZjz0AZDN9tg== | ||
| dependencies: | ||
| acorn "^8.8.0" | ||
| acorn-jsx "^5.3.2" | ||
| eslint-visitor-keys "^3.3.0" | ||
| eslint-visitor-keys "^3.4.0" | ||
|
|
||
| esprima@^4.0.0: | ||
| version "4.0.1" | ||
|
|
@@ -2751,6 +2782,13 @@ esquery@^1.4.0: | |
| dependencies: | ||
| estraverse "^5.1.0" | ||
|
|
||
| esquery@^1.4.2: | ||
| version "1.5.0" | ||
| resolved "https://registry.yarnpkg.com/esquery/-/esquery-1.5.0.tgz#6ce17738de8577694edd7361c57182ac8cb0db0b" | ||
| integrity sha512-YQLXUplAwJgCydQ78IMJywZCceoqk1oH01OERdSAJc/7U2AylwjhSCLDEtqwg811idIS/9fIU5GjG73IgjKMVg== | ||
| dependencies: | ||
| estraverse "^5.1.0" | ||
|
|
||
| esrecurse@^4.3.0: | ||
| version "4.3.0" | ||
| resolved "https://registry.npmjs.org/esrecurse/-/esrecurse-4.3.0.tgz" | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Create range for entire document not just for the selected text.