Skip to content
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

ark: Autocomplete of environment variables not working for Sys.getenv() #4677

Closed
noamross opened this issue Sep 13, 2024 · 2 comments
Closed
Assignees
Labels
area: kernels Issues related to Jupyter kernels and LSP servers lang: r usability

Comments

@noamross
Copy link

noamross commented Sep 13, 2024

tl;dr: In https://github.com/posit-dev/ark/blob/398cfb945edb6d0be4552929c30e346c794ec517/crates/ark/src/modules/positron/completions.R#L76-L83, changing "x" to "x = NULL" fixes autocompletion. Will PR if desired.

System details:

Positron and OS details:

Positron Version: 2024.09.0 (Universal) build 27
Code - OSS Version: 1.92.0
Commit: d996153
Date: 2024-09-11T02:38:46.408Z (2 days ago)
Electron: 30.1.2
Chromium: 124.0.6367.243
Node.js: 20.14.0
V8: 12.4.254.20-electron.0
OS: Darwin arm64 23.6.0

Interpreter details:

R 4.4.1

Describe/Steps to reproduce the issue:

In an R script, Quarto document R cell, or console, typing Sys.getenv( and pressing TAB does not present environment variables for autocompletion:

Screenshot 2024-09-13 at 11 53 46 AM

It does work for Sys.setenv:

Screenshot 2024-09-13 at 11 53 34 AM

Completions also work for library(), options(), and getOption().

It does not matter if I prefix Sys.getenv( with base:: or base:::.

I can retrieve the custom completion:

> .ps.completions.getCustomCallCompletions("Sys.getenv", "x", "name")
[[1]]
 [1] "_"                                  "__CF_USER_TEXT_ENCODING"           
 [3] "__CFBundleIdentifier"               "COLORTERM"                         
 [5] "COMMAND_MODE"                       "DISPLAY"                           
 [7] "EDITOR"                             "ELECTRON_RUN_AS_NODE"              
 [9] "GIT_ASKPASS"                        "HOME"                              
[11] "HOMEBREW_CELLAR"                    "HOMEBREW_PREFIX"                   
[13] "HOMEBREW_REPOSITORY"                "INFOPATH"                          
[15] "LANG"                               "LN_S"                              
[17] "LOGNAME"                            "MAKE"                              
[19] "MallocNanoZone"                     "OLDPWD"                            
[21] "ORIGINAL_XDG_CURRENT_DESKTOP"       "PAGER"                             
[23] "PATH"                               "POSITRON"                          
[25] "POSITRON_VERSION"                   "PWD"                               
[27] "R_BROWSER"                          "R_BZIPCMD"                         
[29] "R_GZIPCMD"                          "R_HOME"                            
[31] "R_LIBS_SITE"                        "R_LIBS_USER"                       
[33] "R_PAPERSIZE"                        "R_PDFVIEWER"                       
[35] "R_PLATFORM"                         "R_PRINTCMD"                        
[37] "R_QPDF"                             "R_RD4PDF"                          
[39] "R_SESSION_TMPDIR"                   "R_STRIP_SHARED_LIB"                
[41] "R_STRIP_STATIC_LIB"                 "R_TEXI2DVICMD"                     
[43] "R_UNZIPCMD"                         "R_ZIPCMD"                          
[45] "RSTUDIO_PANDOC"                     "RUST_BACKTRACE"                    
[47] "RUST_LOG"                           "SED"                               
[49] "SHELL"                              "SHLVL"                             
[51] "SSH_ASKPASS"                        "SSH_AUTH_SOCK"                     
[53] "SUDO_ASKPASS"                       "TAR"                               
[55] "TERM"                               "TERM_PROGRAM"                      
[57] "TERM_PROGRAM_VERSION"               "TMPDIR"                            
[59] "USER"                               "VSCODE_AMD_ENTRYPOINT"             
[61] "VSCODE_CODE_CACHE_PATH"             "VSCODE_CRASH_REPORTER_PROCESS_TYPE"
[63] "VSCODE_CWD"                         "VSCODE_GIT_ASKPASS_EXTRA_ARGS"     
[65] "VSCODE_GIT_ASKPASS_MAIN"            "VSCODE_GIT_ASKPASS_NODE"           
[67] "VSCODE_GIT_IPC_HANDLE"              "VSCODE_HANDLES_UNCAUGHT_ERRORS"    
[69] "VSCODE_IPC_HOOK"                    "VSCODE_NLS_CONFIG"                 
[71] "VSCODE_PID"                         "XDG_CACHE_HOME"                    
[73] "XDG_CONFIG_HOME"                    "XDG_DATA_HOME"                     
[75] "XPC_FLAGS"                          "XPC_SERVICE_NAME"                  
[77] "ZDOTDIR"                           

[[2]]
[1] "unknown"

[[3]]
[1] TRUE

[[4]]
[1] ""

I am also able to register new completions:

Screenshot 2024-09-13 at 12 12 33 PM

However, running the completion definition at https://github.com/posit-dev/ark/blob/398cfb945edb6d0be4552929c30e346c794ec517/crates/ark/src/modules/positron/completions.R#L76-L83 manually does not work:

Screenshot 2024-09-13 at 12 16 39 PM

If I insert a print statement into the callback for the Sys.getenv() completion, it does not print when I press tab. But it does for the cos() example above, so I guess the custom completion is not being called.


OK, after some digging, I find that the name argument being passed to the custom completion handler is x = NULL, not x, so the following does work:

Screenshot 2024-09-13 at 1 10 34 PM

I could PR this into ark, but I don't know if this is the desired setup, or something should change so that the name passed to the handler does not include default arguments. Also, why sign a contributor license agreement for 7 characters?

(While you're add it, I'd suggest adding a handler for Sys.unsetenv() 😉).

Were there any error messages in the UI, Output panel, or Developer Tools console?

No errors. Here is what appears in the "Positron Language Server: R 4.4.1" output pane when TAB is pressed after Sys.getenv(:

[Info  - 12:23:48 PM] Completion(
    CompletionParams {
        text_document_position: TextDocumentPositionParams {
            text_document: TextDocumentIdentifier {
                uri: Url {
                    scheme: "untitled",
                    cannot_be_a_base: true,
                    username: "",
                    password: None,
                    host: None,
                    port: None,
                    path: "Untitled-1",
                    query: None,
                    fragment: None,
                },
            },
            position: Position {
                line: 1,
                character: 11,
            },
        },
        work_done_progress_params: WorkDoneProgressParams {
            work_done_token: None,
        },
        partial_result_params: PartialResultParams {
            partial_result_token: None,
        },
        context: Some(
            CompletionContext {
                trigger_kind: Invoked,
                trigger_character: None,
            },
        ),
    },
)
[Info  - 12:23:48 PM] Completion context: DocumentContext {
    document: Document {
        contents: [
            "\nSys.getenv(\n\n",
        ],
        ast: {Tree {Node program (1, 0) - (3, 0)}},
    },
    node: {Node ( (1, 10) - (1, 11)},
    point: Point {
        row: 1,
        column: 11,
    },
    trigger: None,
}
[Info  - 12:23:48 PM] CompletionResolve(
    CompletionItem {
        label: "x = ",
        label_details: None,
        kind: Some(
            Field,
        ),
        detail: None,
        documentation: None,
        deprecated: None,
        preselect: None,
        sort_text: Some(
            "1-0-x",
        ),
        filter_text: Some(
            "x",
        ),
        insert_text: Some(
            "x = ",
        ),
        insert_text_format: Some(
            Snippet,
        ),
        insert_text_mode: None,
        text_edit: None,
        additional_text_edits: None,
        command: None,
        commit_characters: None,
        data: Some(
            Object {
                "Parameter": Object {
                    "name": String("x"),
                    "function": String("Sys.getenv"),
                },
            },
        ),
        tags: None,
    },
)

Here is what appears for Sys.setenv(:

[Info  - 12:25:33 PM] Completion(
    CompletionParams {
        text_document_position: TextDocumentPositionParams {
            text_document: TextDocumentIdentifier {
                uri: Url {
                    scheme: "untitled",
                    cannot_be_a_base: true,
                    username: "",
                    password: None,
                    host: None,
                    port: None,
                    path: "Untitled-1",
                    query: None,
                    fragment: None,
                },
            },
            position: Position {
                line: 1,
                character: 11,
            },
        },
        work_done_progress_params: WorkDoneProgressParams {
            work_done_token: None,
        },
        partial_result_params: PartialResultParams {
            partial_result_token: None,
        },
        context: Some(
            CompletionContext {
                trigger_kind: Invoked,
                trigger_character: None,
            },
        ),
    },
)
[Info  - 12:25:33 PM] Completion context: DocumentContext {
    document: Document {
        contents: [
            "\nSys.setenv()\n\n",
        ],
        ast: {Tree {Node program (1, 0) - (3, 0)}},
    },
    node: {Node ( (1, 10) - (1, 11)},
    point: Point {
        row: 1,
        column: 11,
    },
    trigger: None,
}
[Info  - 12:25:33 PM] CompletionResolve(
    CompletionItem {
        label: "COLORTERM",
        label_details: None,
        kind: None,
        detail: None,
        documentation: None,
        deprecated: None,
        preselect: None,
        sort_text: Some(
            "1-COLORTERM",
        ),
        filter_text: None,
        insert_text: Some(
            "COLORTERM = ",
        ),
        insert_text_format: Some(
            PlainText,
        ),
        insert_text_mode: None,
        text_edit: None,
        additional_text_edits: None,
        command: None,
        commit_characters: None,
        data: Some(
            String("Unknown"),
        ),
        tags: None,
    },
)
@noamross noamross changed the title Autocomplete of environment variables not working for Sys.getenv() ark: Autocomplete of environment variables not working for Sys.getenv() Sep 13, 2024
@jennybc jennybc added lang: r usability area: kernels Issues related to Jupyter kernels and LSP servers labels Sep 13, 2024
@DavisVaughan
Copy link
Contributor

@noamross we will probably adjust the internals so that you really can just put "x" there rather than "x = NULL".

I think I know what the problem is though, it's likely related to our parser though so I'm happy to just handle this one if that's okay with you.

@DavisVaughan DavisVaughan added this to the 2024.10.0 Pre-Release milestone Sep 17, 2024
@DavisVaughan DavisVaughan self-assigned this Sep 17, 2024
DavisVaughan added a commit that referenced this issue Sep 24, 2024
@testlabauto
Copy link
Contributor

Verified Fixed

Positron Version(s) : 2024.09.0-95
OS Version          : OSX

Test scenario(s)

TAB presents list now with Sys.getenv(

Link(s) to TestRail test cases run or created:

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: kernels Issues related to Jupyter kernels and LSP servers lang: r usability
Projects
None yet
Development

No branches or pull requests

4 participants