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

Added a basic Autocompletion to the script window #8658

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions instat/static/InstatObject/R/stand_alone_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -3000,3 +3000,29 @@ getExample <- function (topic, package = NULL, lib.loc = NULL, character.only =
}
return(example_text)
}

get_list_all_env_names <- function(){
# Get the list of objects in the global environment
objects_list <- ls()

# Get the list of attached packages
attached_packages <- search()
attached_packages <- c(attached_packages, "package:base")

# Extract package names from the search path
package_names <- sapply(strsplit(attached_packages, ":"), function(x) tail(x, 1))

# Get the list of functions in the attached packages
functions_list <- character(0) # Initialize an empty character vector
for (package in package_names) {
if (require(package, character.only = TRUE)){
functions_list <- c(functions_list, ls(paste0("package:", package)))
}
}
sd_alone_func <- ls()

# Combine the lists
combined_list <- c(objects_list, package_names, functions_list, sd_alone_func)
return(combined_list)
}

44 changes: 44 additions & 0 deletions instat/ucrScript.vb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Imports System.IO
Imports System.Windows.Controls
Imports RScript
Imports ScintillaNET
Imports RDotNet

Public Class ucrScript

Expand All @@ -27,6 +28,8 @@ Public Class ucrScript
Private Const iTabIndexLog As Integer = 0
Private strRInstatLogFilesFolderPath As String = Path.Combine(Path.GetFullPath(FileIO.SpecialDirectories.MyDocuments), "R-Instat_Log_files")

Private lstEnvNames As List(Of String)

Friend WithEvents clsScriptActive As Scintilla
Friend WithEvents clsScriptLog As Scintilla

Expand Down Expand Up @@ -71,6 +74,8 @@ Public Class ucrScript

'Make the script tab the selected tab
TabControl.SelectTab(1)

GetListEnvNames()
End Sub

Private Sub SetupInitialLayout()
Expand Down Expand Up @@ -758,6 +763,32 @@ Public Class ucrScript
Private Sub clsScriptActive_CharAdded(sender As Object, e As CharAddedEventArgs) Handles clsScriptActive.CharAdded
InsertMatchedChars(ChrW(e.Char))
InsertIndent(e.Char)

Dim currentPos = clsScriptActive.CurrentPosition
Dim wordStartPos = clsScriptActive.WordStartPosition(currentPos, True)

' Display the autocompletion list
Dim lenEntered = currentPos - wordStartPos
If lenEntered > 0 Then
If Not clsScriptActive.AutoCActive Then
clsScriptActive.AutoCShow(lenEntered, String.Join(" ", lstEnvNames))
End If
End If
End Sub

Private Sub GetListEnvNames()
Dim clsListEnvNamesFunction As New RFunction
Dim chrDataFrameNames As CharacterVector = Nothing
Dim expNames As SymbolicExpression

lstEnvNames = New List(Of String)

clsListEnvNamesFunction.SetRCommand("get_list_all_env_names")
expNames = frmMain.clsRLink.RunInternalScriptGetValue(clsListEnvNamesFunction.ToScript(), bSilent:=True)
If expNames IsNot Nothing AndAlso Not expNames.Type = Internals.SymbolicExpressionType.Null Then
chrDataFrameNames = expNames.AsCharacter
lstEnvNames.AddRange(chrDataFrameNames)
End If
End Sub

Private Sub clsScriptActive_TextChanged(sender As Object, e As EventArgs) Handles clsScriptActive.TextChanged
Expand Down Expand Up @@ -921,6 +952,17 @@ Public Class ucrScript
End If

RunScript(clsScriptActive.Text, "Code run from Script Window (all text)")

SetFocusAndScrollCaret()
End Sub

' Ensure the cursor is visible by scrolling it into view
Private Sub SetFocusAndScrollCaret()
' Set focus back to the ScintillaNET editor control
clsScriptActive.Focus()

' Ensure the cursor is visible by scrolling it into view
clsScriptActive.ScrollCaret()
End Sub

Private Sub mnuRunCurrentStatementSelection_Click(sender As Object, e As EventArgs) Handles mnuRunCurrentStatementSelection.Click, cmdRunStatementSelection.Click
Expand All @@ -929,6 +971,8 @@ Public Class ucrScript
Else
RunCurrentStatement()
End If

SetFocusAndScrollCaret()
End Sub

Private Sub cmdSave_Click(sender As Object, e As EventArgs) Handles cmdSave.Click
Expand Down
Loading