belav / csharpier

CSharpier is an opinionated code formatter for c#.
https://csharpier.com
MIT License
1.42k stars 99 forks source link

VS Code formatting taking a long time #965

Open HrvojeJuric opened 1 year ago

HrvojeJuric commented 1 year ago

Been experiencing this on a work repo but I've been getting this: image

on this repro.

I have these extensions installed:

arcanis.vscode-zipfs
bbenoist.Nix
bmalehorn.shell-syntax
ChakrounAnas.turbo-console-log
codezombiech.gitignore
charliermarsh.ruff
csharpier.csharpier-vscode
ctcuff.font-preview
DavidWang.ini-for-vscode
dbaeumer.vscode-eslint
EditorConfig.EditorConfig
eeyore.yapf
emilast.LogFileHighlighter
Equinusocio.vsc-community-material-theme
esbenp.prettier-vscode
formulahendry.dotnet-test-explorer
foxundermoon.shell-format
gamunu.vscode-yarn
GitHub.copilot
GraphQL.vscode-graphql
GraphQL.vscode-graphql-syntax
jock.svg
letrieu.expand-region
logerfo.sln-support
meganrogge.template-string-converter
mikestead.dotenv
ms-azuretools.vscode-docker
ms-dotnettools.csharp
ms-dotnettools.vscode-dotnet-runtime
ms-ossdata.vscode-postgresql
ms-playwright.playwright
ms-pyright.pyright
ms-python.python
ms-vscode-remote.remote-containers
ms-vscode-remote.remote-ssh
ms-vscode-remote.remote-ssh-edit
ms-vscode-remote.remote-wsl
ms-vscode.powershell
ms-vscode.remote-explorer
naumovs.color-highlight
PKief.material-icon-theme
redhat.vscode-yaml
rust-lang.rust-analyzer
selcukermaya.se-csproj-extensions
shd101wyy.markdown-preview-enhanced
silesky.toggle-boolean
sissel.shopify-liquid
styled-components.vscode-styled-components
stylelint.vscode-stylelint
tamasfe.even-better-toml
TheNuProjectContributors.vscode-nushell-lang
timonwong.shellcheck
tomoki1207.pdf
unifiedjs.vscode-mdx
unifiedjs.vscode-remark
usernamehw.errorlens
vadimcn.vscode-lldb
vscodevim.vim
wayou.vscode-todo-highlight

And these settings:

{
  // intro
  "security.workspace.trust.untrustedFiles": "open",
  "telemetry.telemetryLevel": "off",
  "dotnetAcquisitionExtension.enableTelemetry": false,
  "dotnet-test-explorer.enableTelemetry": false,
  "redhat.telemetry.enabled": false,
  "workbench.settings.editor": "json",
  "git.enabled": false,

  // appearance
  "workbench.iconTheme": "material-icon-theme",
  "workbench.colorTheme": "Community Material Theme Palenight High Contrast",
  "editor.fontSize": 16,
  "editor.fontFamily": "\"JetBrainsMono Nerd Font\",Consolas",
  "editor.fontLigatures": true,
  "debug.console.fontSize": 16,
  "debug.console.fontFamily": "\"JetBrainsMono Nerd Font\",Consolas",
  "terminal.integrated.fontSize": 16,
  "terminal.integrated.fontFamily": "\"JetBrainsMono Nerd Font\",Consolas",
  "editor.lineNumbers": "off",
  "zenMode.hideTabs": false,
  "editor.minimap.enabled": false,
  "workbench.panel.defaultLocation": "right",

  // ergonomics
  "explorer.confirmDragAndDrop": false,
  "search.useIgnoreFiles": false,
  "editor.inlineSuggest.enabled": true,
  "workbench.startupEditor": "readme",
  "editor.acceptSuggestionOnCommitCharacter": false,
  "window.zoomLevel": 1,
  "editor.stickyScroll.enabled": true,
  "editor.linkedEditing": true,
  "editor.suggest.insertMode": "replace",
  "editor.codeActionsOnSave": {
    "source.organizeImports": true,
    "source.addMissingImports": true,
    "source.removeUnusedImports": true
  },

  // remote
  "remote.SSH.configFile": "~/AppData/Roaming/code_ssh_config",
  "search.followSymlinks": false,

  // saving
  "files.hotExit": "onExitAndWindowClose",
  "files.autoSave": "onFocusChange",
  "task.saveBeforeRun": "always",
  "debug.saveBeforeStart": "nonUntitledEditorsInActiveGroup",
  "testing.saveBeforeTest": true,
  "files.enableTrash": true,
  "explorer.confirmDelete": false,

  // file format
  "files.insertFinalNewline": true,
  "files.encoding": "utf8",
  "files.eol": "\n",
  "editor.rulers": [
    {
      "column": 80,
      "color": "#CCCCDD"
    }
  ],
  "editor.tabSize": 2,
  "editor.wordWrap": "off",
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "editor.formatOnSave": true,

  // vim
  "vim.leader": "<space>",
  "vim.foldfix": true,
  "vim.hlsearch": true,
  "vim.useSystemClipboard": true,
  "vim.highlightedyank.enable": true,
  "vim.sneak": true,
  "vim.textwidth": 80,
  "vim.insertModeKeyBindingsNonRecursive": [
    {
      "before": ["j", "k"],
      "after": ["<Esc>", "workbench.action.files.save"]
    }
  ],
  "vim.normalModeKeyBindingsNonRecursive": [
    {
      "before": ["<leader>", "f"],
      "commands": ["workbench.action.quickOpen"]
    },
    {
      "before": ["<leader>", "k"],
      "commands": ["editor.action.showHover"]
    },
    {
      "before": ["<leader>", "c", "a"],
      "commands": ["editor.action.quickFix"]
    },
    {
      "before": ["[", "d"],
      "commands": ["editor.action.marker.prev"]
    },
    {
      "before": ["]", "d"],
      "commands": ["editor.action.marker.next"]
    },
    {
      "before": ["<leader>", "s", "d"],
      "commands": ["workbench.action.splitEditorDown"]
    },
    {
      "before": ["<leader>", "s", "l"],
      "commands": ["workbench.action.splitEditorLeft"]
    },
    {
      "before": ["<leader>", "s", "u"],
      "commands": ["workbench.action.splitEditorUp"]
    },
    {
      "before": ["<leader>", "s", "r"],
      "commands": ["workbench.action.splitEditorRight"]
    }
  ],
  "vim.commandLineModeKeyBindingsNonRecursive": [
    {
      "before": ["dbg"],
      "commands": ["workbench.action.debug.start"]
    }
  ],

  // helix

  // terminal
  "terminal.integrated.profiles.windows": {
    "Nushell": {
      "path": "C:\\Program Files\\nu\\bin\\nu.exe"
    },
    "PowerShell": {
      "source": "PowerShell",
      "icon": "terminal-powershell"
    },
    "Command Prompt": {
      "path": [
        "${env:windir}\\Sysnative\\cmd.exe",
        "${env:windir}\\System32\\cmd.exe"
      ],
      "args": [],
      "icon": "terminal-cmd"
    },
    "Git Bash": {
      "source": "Git Bash"
    }
  },
  "terminal.integrated.defaultProfile.windows": "PowerShell",
  "terminal.explorerKind": "external",
  "terminal.external.windowsExec": "alacritty",
  "terminal.integrated.gpuAcceleration": "on",
  "workbench.colorCustomizations": {
    "debugConsole.errorForeground": "#ff0000",
    "debugConsole.infoForeground": "#00ff00",
    "debugConsole.warningForeground": "#ffff00",
    "debugConsole.sourceForeground": "#ffffff"
  },
  "debug.terminal.clearBeforeReusing": true,

  // language specific
  "github.copilot.enable": {
    "*": true,
    "yaml": true,
    "plaintext": false,
    "markdown": true
  },
  "[shellscript]": {
    "editor.defaultFormatter": "foxundermoon.shell-format"
  },
  "[dotenv]": {
    "editor.defaultFormatter": "foxundermoon.shell-format"
  },
  "[ignore]": {
    "editor.defaultFormatter": "foxundermoon.shell-format"
  },
  "[csharp]": {
    "editor.defaultFormatter": "csharpier.csharpier-vscode"
  },
  "[jsonc]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "typescript.updateImportsOnFileMove.enabled": "always",
  "typescript.preferences.importModuleSpecifier": "project-relative",
  "javascript.updateImportsOnFileMove.enabled": "always",
  "javascript.preferences.importModuleSpecifier": "project-relative",
  "powershell.promptToUpdatePowerShell": false,
  "remote.SSH.remotePlatform": {
    "pidgeon": "linux"
  }
}

.csharpier.yaml:

printWidth: 80
useTabs: false
tabWidth: 2
preprocessorSymbolSets:
  - ""
  - "DEBUG"
  - "DEBUG,CODE_STYLE"

Other formatters like prettier work just fine (ie. on .csharpier.yaml).

EDIT: fix repro link EDIT2: add other formatter clarification

belav commented 1 year ago

I grabbed your repo + used the settings file and formatting is working for me. Does the output - CSharpier window provide any clues on why it takes so long? And does it eventually finish?

I'm guessing the problem is either a conflict with another extension, or perhaps the extension is unhappy if you are doing remote ssh work. I did make some changes to detect when devcontainers, it could be a similar problem with remote ssh - https://github.com/belav/csharpier/commit/0a58405baf1070cfb387ddfa60d96eda68d4b17b

If it is a conflict with an extension, then hopefully the output window provides some useful information.

AkiraVoid commented 1 year ago

@belav I guess the author used WSL 2 to code. May you have a try with WSL 2? I encountered the same problem with it, and by the way, running dotnet csharpier directly in WSL terminal seems fine.


Edit:

I got this output while initialization:

Exception while running 'dotnet csharpier --version' in /home/akiravoid/.cache/csharpier/0.25.0
"You must install .NET to run this application.

App: /home/akiravoid/.cache/csharpier/0.25.0/dotnet-csharpier
Architecture: x64
App host version: 8.0.0-rc.2.23479.6
.NET location: Not found

Learn more:
https://aka.ms/dotnet/app-launch-failed

Download the .NET runtime:
https://aka.ms/dotnet-core-applaunch?missing_runtime=true&arch=x64&rid=linux-x64&os=ubuntu.20.04&apphost_version=8.0.0-rc.2.23479.6
"

I guess that this may be caused by wrong .NET version. But I have installed 7.0 and 6.0 on my Linux distro, and it still get this exception.

And this command is executed here: https://github.com/belav/csharpier/blob/4e4bb4dd425f9d2b8b94c34b0593289b9b11c05c/Src/CSharpier.VSCode/src/CustomPathInstaller.ts#L13-L47


Edit:

I got a full debug log:

["INFO" - 5:47:42 PM] Initializing csharpier-vscode
["INFO" - 5:47:53 PM] Formatting started for /home/akiravoid/projects/animaid-core/lib/AkiraVoid.Animaid.Core/Enums/ActorType.cs.
["DEBUG" - 5:47:53 PM] Ensure there is a csharpier process for /home/akiravoid/projects/animaid-core/lib/AkiraVoid.Animaid.Core/Enums
["DEBUG" - 5:47:53 PM] Looking for /home/akiravoid/projects/animaid-core/lib/AkiraVoid.Animaid.Core/Enums/*.csproj
["DEBUG" - 5:47:53 PM] Looking for /home/akiravoid/projects/animaid-core/lib/AkiraVoid.Animaid.Core/Enums/.config/dotnet-tools.json
["DEBUG" - 5:47:53 PM] Looking for /home/akiravoid/projects/animaid-core/lib/AkiraVoid.Animaid.Core/*.csproj
["DEBUG" - 5:47:53 PM] Looking at /home/akiravoid/projects/animaid-core/lib/AkiraVoid.Animaid.Core/AkiraVoid.Animaid.Core.csproj
["DEBUG" - 5:47:53 PM] Looking for /home/akiravoid/projects/animaid-core/lib/AkiraVoid.Animaid.Core/.config/dotnet-tools.json
["DEBUG" - 5:47:53 PM] Looking for /home/akiravoid/projects/animaid-core/lib/*.csproj
["DEBUG" - 5:47:53 PM] Looking for /home/akiravoid/projects/animaid-core/lib/.config/dotnet-tools.json
["DEBUG" - 5:47:53 PM] Looking for /home/akiravoid/projects/animaid-core/*.csproj
["DEBUG" - 5:47:53 PM] Looking for /home/akiravoid/projects/animaid-core/.config/dotnet-tools.json
["DEBUG" - 5:47:53 PM] Found version 0.25.0 in /home/akiravoid/projects/animaid-core/.config/dotnet-tools.json
["WARN" - 5:47:53 PM] Exception while running 'dotnet csharpier --version' in /home/akiravoid/.cache/csharpier/0.25.0
"You must install .NET to run this application.\n\nApp: /home/akiravoid/.cache/csharpier/0.25.0/dotnet-csharpier\nArchitecture: x64\nApp host version: 8.0.0-rc.2.23479.6\n.NET location: Not found\n\nLearn more:\nhttps://aka.ms/dotnet/app-launch-failed\n\nDownload the .NET runtime:\nhttps://aka.ms/dotnet-core-applaunch?missing_runtime=true&arch=x64&rid=linux-x64&os=ubuntu.20.04&apphost_version=8.0.0-rc.2.23479.6\n"
["DEBUG" - 5:47:53 PM] Removing directory at /home/akiravoid/.cache/csharpier/0.25.0 because it appears to be corrupted
["DEBUG" - 5:47:57 PM] Adding new version 0.25.0 process for /home/akiravoid/projects/animaid-core/lib/AkiraVoid.Animaid.Core/Enums
["DEBUG" - 5:47:57 PM] Warm CSharpier with initial format

Output of dotnet --info on my WSL distro:

.NET SDK:
 Version:   8.0.100-rc.2.23502.2
 Commit:    0abacfc2b6

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  20.04
 OS Platform: Linux
 RID:         linux-x64
 Base Path:   /home/akiravoid/.dotnet/sdk/8.0.100-rc.2.23502.2/

.NET workloads installed:
There are no installed workloads to display.

Host:
  Version:      8.0.0-rc.2.23479.6
  Architecture: x64
  Commit:       0b25e38ad3

.NET SDKs installed:
  6.0.415 [/home/akiravoid/.dotnet/sdk]
  7.0.402 [/home/akiravoid/.dotnet/sdk]
  8.0.100-rc.2.23502.2 [/home/akiravoid/.dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.23 [/home/akiravoid/.dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.12 [/home/akiravoid/.dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.0-rc.2.23480.2 [/home/akiravoid/.dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.23 [/home/akiravoid/.dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.12 [/home/akiravoid/.dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.0-rc.2.23479.6 [/home/akiravoid/.dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download

I made a startup vscode extension project with yo code, added these lines:

let dotnet: Buffer;
try {
    dotnet = execSync("dotnet csharpier --version", {
        cwd: "/home/akiravoid/projects/animaid-core",
        env: process.env,
    });
} catch (error) {
    console.error(error);
    throw error;
}

console.log(dotnet.toString("utf-8"));

It prints 0.25.0, which is expected.