question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

onsave sometimes stops working until I restart VSCode

See original GitHub issue

Hi

I have these configs in my workspace settings:

		"php-cs-fixer.config": "..\\myrepo\\phpcsfixer.php",
		"php-cs-fixer.executablePath": "${workspaceFolder}\\..\\myrepo\\vendor\\bin\\php-cs-fixer.bat",
		"php-cs-fixer.onsave": true,
		"php-cs-fixer.allowRisky": true,

and my phpcsfixer.php:

$config = new PhpCsFixer\Config();
return $config
	->setIndent("\t")
	->setLineEnding("\n")
	->setRules([
(...)
	])
	->setFinder(
		PhpCsFixer\Finder::create()
			->exclude('vendor')
			->in(__DIR__)
	);

Many times, the “onsave” seems to stop working. If I restart VSCode, it works again, but eventually stops working again.

When it works, I can see an output like:

(if there is something to fix)

[
  "fix",
  "--using-cache=no",
  "--format=json",
  "--config=f:\\Files\\Git\\myrepo/..\\myrepo\\phpcsfixer.php",
  "--allow-risky=yes",
  "--path-mode=override",
  "C:\\Users\\myuser\\AppData\\Local\\Temp/myfile.php"
]
{"files":[{"name":"C:\\Users\\myuser\\AppData\\Local\\Temp\\myfile.php"}],"time":{"total":0.104},"memory":14}

(if there is not something to fix)

[
  "fix",
  "--using-cache=no",
  "--format=json",
  "--config=f:\\Files\\Git\\myrepo/..\\myrepo\\phpcsfixer.php",
  "--allow-risky=yes",
  "--path-mode=override",
  "C:\\Users\\myuser\\AppData\\Local\\Temp/myfile.php"
]
{"files":[],"time":{"total":0.079},"memory":14}
Loaded config default from "f:\Files\Git\myrepo/..\myrepo\phpcsfixer.php".
Paths from configuration file have been overridden by paths provided as command arguments.

But when it stops working, there’s no output at all, and the issues stay on the file.

Any ideas why? Or where I can check for any errors.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:2
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
junstylecommented, Jul 18, 2022

open the developer tools, can you see some error logs? please upload next time, otherwise i can’t find the problem.

if you enable "php-cs-fixer.onsave": true, you must make sure "editor.formatOnSave": false first

so i think the best way to format code on save, it enables formattingProvider, settings like these:

"php-cs-fixer.onsave": false,
"php-cs-fixer.documentFormattingProvider": true,
"[php]": {
  "editor.formatOnSave": true,
  "editor.defaultFormatter": "junstyle.php-cs-fixer"
}

you can try

the onsave setting is compatible with early versions.

0reactions
bradrogancommented, Jul 27, 2022

@junstyle same here, it seems things are good with your suggestions. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Errors no longer clearing · Issue #1036 · microsoft/vscode-go
Restarting visual code; Disabling coverOnSave; Deleting the test file (coverage still shows up in the editor, can't seem to clear it); ps aux...
Read more >
save not doing anything - Visual Studio Feedback
After closing vs2015 and restarting visual studio 2017 the problem seems to have gone away. ... it randomly starts to work again (though...
Read more >
VS Code - Intellisense stopped working, takes 4-5 seconds ...
go to File > Preferences > Settings (macOS: Code > Preferences > Settings), search for update mode and change the setting to none....
Read more >
So, my development experience is just getting worse after ...
Intellisense freezing is something that always happened to VS, ever since old versions. To fix that, just call the "Restart TS Server" command....
Read more >
How to Format Code on Save in VS Code with ESlint
This reloads your VS Code window rather than restarting the JavaScript and TypeScript language servers. ESLint Still Not Formatting on Save? I' ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found