robotcodedev / robotcode

RobotFramework support for Visual Studio Code
https://robotcode.io
Apache License 2.0
182 stars 15 forks source link

[QUESTION] Too many blank lines at the of file #124

Closed Austriker closed 1 year ago

Austriker commented 1 year ago

Please describe. Hello

I fighting with the end of file spaces. When I save it adds 2 new lines while it should be adding 1 new line.

Then I get this warning: Too many blank lines at the end of file robocop(W1010)

I tried disabling this through the vscode settings but I still get 2 new lines.

vscode settings:

{
    "editor.formatOnSave": true,
    "editor.rulers": [
        80
    ],
    "python.linting.pylintEnabled": false,
    "python.linting.flake8Enabled": true,
    "python.linting.mypyEnabled": true,
    "python.formatting.provider": "black",
    "python.defaultInterpreterPath": "/usr/local/bin/python",
    "[python]": {
        "editor.codeActionsOnSave": {
            "source.organizeImports": true
        },
        "editor.rulers": [
            88
        ]
    },
    "files.exclude": {
        "**/__pycache__": true,
        "**/.git": true,
        ".cache/**": true,
        ".sonar/**": true
    },
    "files.watcherExclude": {
        "**/__pycache__": true,
        "**/.git/objects/**": true,
        "**/.git/subtree-cache/**": true,
        "**/env/**": true
    },
    "files.eol": "\n",
    "files.insertFinalNewline": true,
    "[robotframework]": {
        "files.insertFinalNewline": false
    },
    "terminal.integrated.defaultProfile.linux": "bash",
    "robotcode.robot.pythonPath": [
        "./libraries",
        "./resources",
        "./configs",
    ]
}

Desktop (please complete the following information):

d-biehl commented 1 year ago

can you disable the "editor.formatOnSave": true and see what happens? sometime robotidy has some problems the last line of the file.

d-biehl commented 1 year ago

does it work?

Austriker commented 1 year ago

@d-biehl sorry for the late reply.

So If I remove the formatOnSave the file is not formatted anymore and the number of lines stays the same.

Other test I did is to set "files.insertFinalNewline": false when I save the number of new lines is OK but if there is too many new lines then I get 2 new lines at the end of the file.

bhirsz commented 1 year ago

We (Robotidy) had some problems with end of lines in the past but now it should work correctly (at least no one is reporting anything :) ). It looks like both this plugin and Robotidy are trying to do the same action (files.insertFinalNewline is something done by plugin, where Robotidy also adds new line).

If you have specific code it keeps on happening I can check it on Robotidy side (without robotcode extension).

d-biehl commented 1 year ago

I fixed a small bug, @Austriker can you check if it works correctly now?

Austriker commented 1 year ago

Yeah I will have a look on Monday !

Thank you !

Le ven. 7 avr. 2023, 23:32, Daniel Biehl @.***> a écrit :

I fixed a small bug, @Austriker https://github.com/Austriker can you check if it works correctly now?

— Reply to this email directly, view it on GitHub https://github.com/d-biehl/robotcode/issues/124#issuecomment-1500663697, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGYNAKFYSRGEITPRU6J4JDXACBVTANCNFSM6AAAAAAVMC37MU . You are receiving this because you were mentioned.Message ID: @.***>

Austriker commented 1 year ago

@d-biehl Indentation seems good and blank lines but I am getting threading issues and the next format hangs:

/home/berry/.vscode-server/extensions/d-biehl.robotcode-0.33.0/bundled/libs/robotcode/core/async_tools.py:465: UserWarning: Lock <robotcode.core.async_tools.Lock object at 0x7f575dcfcd60 [locked, waiters:2]> <Task pending name='RobotDiagnosticsProtocolPart.collect_unused_variable_references' coro=<RobotDiagnosticsProtocolPart.collect_unused_variable_references() running at /home/berry/.vscode-server/extensions/d-biehl.robotcode-0.33.0/bundled/libs/robotcode/language_server/robotframework/parts/diagnostics.py:330> wait_for=<Future pending cb=[FutureInfo._done(), Task.task_wakeup()]> cb=[FutureInfo._done(), Task.task_wakeup()]> takes to long <Thread(RobotDiagnosticsProtocolPart.collect_unused_keyword_references, started daemon 140013249492736)>
, try to cancel...
  warnings.warn(f"Lock {self} takes to long {threading.current_thread()}\n, try to cancel...")
/home/berry/.vscode-server/extensions/d-biehl.robotcode-0.33.0/bundled/libs/robotcode/core/async_tools.py:465: UserWarning: Lock <robotcode.core.async_tools.Lock object at 0x7f579018e5f0 [locked, waiters:1]> <Task pending name='Task-4247' coro=<Namespace.resources_changed() running at /home/berry/.vscode-server/extensions/d-biehl.robotcode-0.33.0/bundled/libs/robotcode/language_server/robotframework/diagnostics/namespace.py:656> wait_for=<Future pending cb=[FutureInfo._done(), Task.task_wakeup()]> cb=[FutureInfo._done(), as_completed.<locals>._on_completion() at /usr/local/lib/python3.10/asyncio/tasks.py:558]> takes to long <Thread(diagnostics_worker, started daemon 140014086100736)>
, try to cancel...
  warnings.warn(f"Lock {self} takes to long {threading.current_thread()}\n, try to cancel...")
d-biehl commented 1 year ago

Yes, this is a known error, most of the time the language server will recover, if not it helps to restart the language server. For this in VSCode there is the command "RobotCode: Restart Language Servers" or simply restart VSCode.

I'm working on the bugfix, but I can't promise when it will be finished, because some major refactorings are needed.