Coder Social home page Coder Social logo

Comments (11)

dsherret avatar dsherret commented on May 3, 2024

That seems like a bug with the code that adds the import statement? It should add it on the next line. Does that occur with the dprint plugin disabled?

from dprint-intellij.

prescience-data avatar prescience-data commented on May 3, 2024

No once the plugin is disabled, the IDE behaves normally.

from dprint-intellij.

dsherret avatar dsherret commented on May 3, 2024

I don't understand what this plugin would have to do with putting that import on the incorrect line. @ryan-rushton any ideas?

from dprint-intellij.

prescience-data avatar prescience-data commented on May 3, 2024

Other interesting effects:

1. When "on save" is enabled, it formats the current file but sets every other file in the project to some sort of "compact" format:

"compact" format:
image
correct format:
image

(for clarity - each time a file is corrected, the other files that were previously corrected reset back to this strange "compact" state. this does not appear to occur when using the cli dprint fmt directly)

2. No longer respects "new line" rules after imports:

with dprint plugin:
image

without dprint plugin:
image

from dprint-intellij.

prescience-data avatar prescience-data commented on May 3, 2024

Addtional context

Not sure if any of these might be relevant but thought it might help with isolation:

  • eslint is enabled
  • using pnpm as package manager
  • project is a @microsoft/rush monorepo
  • using .editorconfig file (provided below)

editorconfig file:

root = true

# Global Settings
[*]
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
insert_final_newline = true

# IntelliJ IDE Settings
ij_any_if_brace_force = always
ij_editorconfig_align_group_field_declarations = false
ij_javascript_spaces_within_array_initializer_brackets = true
ij_markdown_force_one_space_after_header_symbol = true
ij_markdown_max_lines_around_block_elements = 1
ij_markdown_max_lines_around_header = 1
ij_markdown_max_lines_between_paragraphs = 1
ij_markdown_min_lines_around_block_elements = 1
ij_markdown_min_lines_around_header = 1
ij_markdown_min_lines_between_paragraphs = 1
ij_typescript_align_imports = false
ij_typescript_array_initializer_wrap = on_every_item
ij_typescript_catch_on_new_line = false
ij_typescript_continuation_indent_size = 2
ij_typescript_blank_lines_after_imports = 1
ij_typescript_else_on_new_line = false
ij_typescript_import_merge_members = true
ij_typescript_indent_chained_calls = true
ij_typescript_indent_size = 2
ij_typescript_jsdoc_include_types = true
ij_typescript_line_comment_add_space = true
ij_typescript_line_comment_at_first_column = true
ij_typescript_space_after_colon = true
ij_typescript_space_after_comma = true
ij_typescript_spaces_within_array_initializer_brackets = true
ij_typescript_spaces_within_imports = true
ij_typescript_use_chained_calls_group_indents = true
ij_typescript_use_public_modifier = false
ij_typescript_while_brace_force = always
ij_typescript_wrap_comments = true
ij_visual_guides = 80, 120, 200
ij_vue_continuation_indent_size = 2
ij_vue_indent_size = 2
ij_vue_interpolation_new_line_after_start_delimiter = true
ij_vue_interpolation_new_line_before_end_delimiter = true
ij_vue_interpolation_wrap = off
ij_vue_keep_indents_on_empty_lines = false
ij_vue_spaces_within_interpolation_expressions = true
ij_vue_tab_width = 2

current dprint.json

{
  "$schema": "https://plugins.dprint.dev/dprint/dprint-plugin-typescript/latest/schema.json",
  "includes": [
    "**/*.{ts,tsx,js,cjs,mjs,vue,json,md}"
  ],
  "excludes": [
    "**/lib/",
    "**/dist/",
    "**/node_modules/",
    "**/jspm_packages/",
    "**/.rush/",
    "**/.heft/",
    "**/.cache/",
    "**/temp/"
  ],
  "incremental": true,
  "indentWidth": 2,
  "useTabs": false,
  "lineWidth": 80,
  "plugins": [
    "https://plugins.dprint.dev/typescript-0.68.2.wasm",
    "https://plugins.dprint.dev/prettier-0.7.0.json@4e846f43b32981258cef5095b3d732522947592e090ef52333801f9d6e8adb33",
    "https://plugins.dprint.dev/json-0.15.2.wasm",
    "https://plugins.dprint.dev/markdown-0.13.2.wasm"
  ],
  "json": {
    "indentWidth": 2
  },
  "prettier": {
    "arrowParens": "always",
    "bracketSpacing": true,
    "endOfLine": "lf",
    "printWidth": 80,
    "proseWrap": "always",
    "semi": false,
    "singleQuote": false,
    "tabWidth": 2,
    "trailingComma": "none",
    "useTabs": false,
    "vueIndentScriptAndStyle": true
  },
  "typescript": {
    "lineWidth": 80,
    "indentWidth": 2,
    "useTabs": false,
    "semiColons": "asi",
    "quoteStyle": "alwaysDouble",
    "trailingCommas": "never",
    "newLineKind": "lf",
    "spaceAround": true,
    "useBraces": "always",
    "taggedTemplate.spaceBeforeLiteral": false,
    "importDeclaration.spaceSurroundingNamedImports": true,
    "constructorType.spaceAfterNewKeyword": true,
    "typeAssertion.spaceBeforeExpression": false,
    "constructor.spaceBeforeParentheses": false
  }
}

Current debugging efforts have been to remove typescript and prettier plugins individually to see if there was any conflict.

from dprint-intellij.

ryan-rushton avatar ryan-rushton commented on May 3, 2024

First, @prescience-data what version of the plugin are you running? There have been a couple of changes that are being evolved atm to integrate into the actual IntelliJ formatter but it isn't complete just yet. I am currently working on improving this with the latest schema version.

If you are on the latest, I thiiink this is due to how the new IntelliJ code refactoring system works. Basically, when refactoring (and I think adding imports is included here) IntelliJ creates a pseudo file with the changes, it tries to run the configured formatter over these. The issue we have is that file won't have a filepath so we don't actually format it. For a setup like this we should just format it anyway but for a repo where some TS files may be formatted and some might not be, we cannot do that. Another option would be to go back to letting IntelliJ format those files, I disabled that recently for a Java issue.

I have noticed this behavior with a custom Java setup we are running but it isn't an issue as semicolons are necessary so it can easily format them.

Also thanks for the report! It is pretty early days for this plugin still so I am stoked people are finding use for it, I will try get this fixed ASAP for you.

from dprint-intellij.

prescience-data avatar prescience-data commented on May 3, 2024

Yeah I noticed if I force semicolons it manages to recover and complete the formatting.

Unfortunately for this project the existing style guide across the team is no semis so I'll keep tinkering around.

Regarding the version, it's just whatever the latest one published to the Jetbrains plugin system is.

Thanks for the info above πŸ•ΊπŸ»

from dprint-intellij.

ryan-rushton avatar ryan-rushton commented on May 3, 2024

All good, I think it is a fairly easy fix in that we will let IntelliJ perform AdHoc formatting (formatting for pseudo files) and we should get around the issue for now.

@dsherret one thing we could do to get around this is to send something to dprint to force a format even if we don't have a file path. This would allow us to perform the AdHoc formatting but we still have the inconsistency where we might partially format something that is ignored in the globs. I will do a bit of digging into the IntelliJ API to see if I can figure out what the destination file path is for AdHoc formatting and maybe we can use that.

from dprint-intellij.

prescience-data avatar prescience-data commented on May 3, 2024

we might partially format something that is ignored in the globs.

Not sure if this would be too "janky", but perhaps if the destination path idea doesn't pan out, it could make a copy of the ignored files, and restore the pre-formatted versions post-format if it notices they have changed?

from dprint-intellij.

ryan-rushton avatar ryan-rushton commented on May 3, 2024

@prescience-data has your issue been fixed with the new version?

from dprint-intellij.

ryan-rushton avatar ryan-rushton commented on May 3, 2024

Closing as stale

from dprint-intellij.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.