REditorSupport / vscode-R

R Extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=REditorSupport.r
MIT License
1.07k stars 128 forks source link

Auto comment new lines when writing block comments with #' #1254

Closed natereal closed 1 year ago

natereal commented 1 year ago

In RStudio, when writing a comment beginning with #', hitting enter will automatically start the next line with #' This is useful for writing Roxygen blocks but also for writing block comments.

I've seen some packages such as Auto Comment Blocks , however some issues with that package are that

I think the default should mirror R Studio, but if this could be added as a configuration option that would be ideal. Is this already an option somewhere that I have missed?

I think it would be very useful if this could happen when hitting 'Enter' and not need another shortcut/package that has to be configured on every machine. I don't want extra dependencies to do something so simple.

ElianHugh commented 1 year ago

This should work already: roxygen

Is this not the behaviour you are experiencing when working with royxgen blocks?

natereal commented 1 year ago

This is the behaviour I expect but it is not working for me. Can you think of any setting that I may have turned off?

andycraig commented 1 year ago

@oduilln Could you share your settings.json? We can have a look to see if any of your settings might be interfering with this feature.

natereal commented 1 year ago

Sure,

{
    "editor.largeFileOptimizations": false,
    "r.rpath.windows": "C:\\Program Files\\R\\R-4.1.2\\bin\\x64\\R.exe",
    "r.rterm.windows": "C:\\Users\\nathan.doyle\\AppData\\Local\\Programs\\Python\\Python38\\Scripts\\radian.exe",
    "r.libPaths": [
        "C:/Program Files/R/R-4.1.2/library"
    ],
    "terminal.integrated.enableMultiLinePasteWarning": false,
    "terminal.integrated.enablePersistentSessions": false,
    "terminal.integrated.defaultProfile.windows": "Git Bash",
    "extensions.autoUpdate": false,
    "r.plot.useHttpgd": true,
    "terminal.integrated.automationShell.windows": "R Terminal",
    "powershell.enableProfileLoading": false,
    "powershell.integratedConsole.showOnStartup": false,
    "terminal.integrated.automationProfile.windows": null,
    "r.bracketedPaste": true,
    "terminal.integrated.automationProfile.osx": {

    },
    "editor.foldingStrategy": "indentation",
    "folding": {
        "offSide": true,
        "markers": {
            "start": "{",
            "end": "}"
        }
    },
    "remote.SSH.configFile": "C:\\Users\\nathan.doyle\\.ssh\\config",
    "python.envFile": "${workspaceFolder}/.venv",
    "git.autofetch": true,
    "r.rterm.linux": "/usr/local/bin/radian",
    "github.gitProtocol": "ssh",
    "r.rpath.linux": "/opt/R/4.1.3/bin/R",
    "diffEditor.ignoreTrimWhitespace": false,
    "workbench.sideBar.location": "right",
    "workbench.editorAssociations": {
        "*.html": "default"
    },
    "editor.autoIndent": "brackets",
    "rewrap.autoWrap.enabled": true,
    "editor.tabCompletion": "on",
    "editor.wordWrap": "on"
}

Some options are from the package 'Rewrap'

andycraig commented 1 year ago

@oduilln Thank you for that info. I tried adding a few of those settings to my own settings.json but I still get the expected behaviour (#' on the new line after hitting Enter).

My guess is that another extension is conflicting with this one. Could you try disabling all of your extensions except this one, and checking if that solves the problem?

natereal commented 1 year ago

When I disabled all extensions I will still getting the same problem.

I went back to the settings JSON and found that once I removed the following two lines:

    //"editor.autoIndent": "brackets",
    //"editor.tabCompletion": "on",

and also disabled all other extensions, it was working as expected.

I am not sure why these lines changed the functionality for me and not for you, but it may have been from one of the extensions I had installed previously. I uninstalled rewrap, and I also had uninstalled some other extensions whose name I have forgotten, so it was potentially one of those causing the issue with the json settings above.

Thank you for your help in debugging this issue!

andycraig commented 1 year ago

@oduilln Great to hear it's sorted out! And thank you for posting those notes about how you resolved it.