Skip to content

Hot key for document formatting stopped working. #1283

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

Closed
vault-thirteen opened this issue Dec 17, 2024 · 5 comments
Closed

Hot key for document formatting stopped working. #1283

vault-thirteen opened this issue Dec 17, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@vault-thirteen
Copy link

Describe the bug
Hot key for document formatting stopped working.

To Reproduce
Steps to reproduce the behaviour:

  1. Install Swift for VSCode.
  2. Create a new Swift project.
  3. Formatting worked in the default project.
  4. After I added a new file Person.swift with sample code, formatting stopped working.

Expected behavior
Document formatting works.

Environment

  • OS: Windows 10 22H2 (OS Build 19045.5247)
  • Swift version: 6.0.2
  • Visual Studio Code version: 1.96.0 (system setup)
  • vscode-swift version:
Identifier sswg.swift-lang
Version 1.11.4
Last Updated 2024-12-16, 21:43:16

Additional context
Contents of the Person.swift file.

class Person {
    var name String
    var age Int

    init(name:String,age:Int){
        self.name=name
           self.age=age
    }
}

Below is the automatically created bug report by the VSCode editor which I sent to VSCode repository.
microsoft/vscode#236349

Type: Bug

Hot key for document formatting stopped working.

Steps to reproduce.

  1. Install Swift for VSCode.
  2. Create a new Swift project.
  3. Formatting worked in the default project.
  4. After I added a new file Person.swift with sample code, formatting stopped working.

Contents of the Person.swift file.

class Person {
    var name String
    var age Int

    init(name:String,age:Int){
        self.name=name
           self.age=age
    }
}

VS Code version: Code 1.96.0 (138f619c86f1199955d53b4166bef66ef252935c, 2024-12-11T02:29:09.626Z)
OS version: Windows_NT x64 10.0.19045
Modes:

System Info
Item Value
CPUs 11th Gen Intel(R) Core(TM) i5-11600KF @ 3.90GHz (12 x 3912)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
webnn: disabled_off
Load (avg) undefined
Memory (System) 31.81GB (26.36GB free)
Process Argv --crash-reporter-id 1a51cee8-c48a-4215-9337-592058824e40
Screen Reader no
VM 0%
Extensions (5)
Extension Author (truncated) Version
debugpy ms- 2024.14.0
python ms- 2024.22.0
vscode-pylance ms- 2024.12.1
swift-lang ssw 1.11.4
vscode-lldb vad 1.11.1
A/B Experiments
vsliv368:30146709
vspor879:30202332
vspor708:30202333
vspor363:30204092
vswsl492:30256859
vscod805:30301674
binariesv615:30325510
vsaa593cf:30376535
py29gd2263:31024239
vscaac:30438847
c4g48928:30535728
azure-dev_surveyone:30548225
vscrpc:30673769
2i9eh265:30646982
962ge761:30959799
pythonnoceb:30805159
pythonmypyd1:30879173
2e7ec940:31000449
pythontbext0:30879054
cppperfnew:31000557
dsvsc020:30976470
pythonait:31006305
dsvsc021:30996838
dvdeprecation:31068756
dwnewjupytercf:31046870
nativerepl1:31139838
pythonrstrctxt:31112756
nativeloc1:31192215
cf971741:31144450
iacca1:31171482
notype1cf:31157160
5fd0e150:31155592
dwcopilot:31170013
stablechunks:31184530
6074i472:31201624

Image
Image

@plemarquand
Copy link
Contributor

plemarquand commented Dec 17, 2024

The formatter does not work on Swift code with syntax errors. This code is missing the colon : before the type on the declaration of name and age

class Person {
    var name: String
    var age: Int
...

Modifying these two lines and formatting the document should work.

@vault-thirteen
Copy link
Author

vault-thirteen commented Dec 17, 2024

The editor does not show me that there are any syntax errors in the file. You can see it in the screenshot, there are no highlighted words or operands.

How do I know that there are any syntax errors without trying to run the code ?

Other IDE's that I use, such as Microsoft Visual Studio and a lot of products of JetBrains company, always show me syntax errors in the editor.

P. S.

I have changed the text and formatting started to work. Thank you for your help.

So, this issue can be renamed as VSCode does not highlight syntax errors in the editor when they are present.
This was the reason of the original issue.

@plemarquand
Copy link
Contributor

I think the diagnostics not appearing is caused by swiftlang/sourcekit-lsp#1855. That fix should work its way into the next Swift release.

@vault-thirteen
Copy link
Author

Thank you @plemarquand

@plemarquand
Copy link
Contributor

Thanks for the report. I'm going to close out the issue, but feel free to comment or open a new one if you see anything else.

@award999 award999 moved this from Unscreened to Done in Swift Extension for Visual Studio Code Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Development

No branches or pull requests

2 participants