Skip to content

Commit

Permalink
fixed all the bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
digital-phoenix committed Jan 17, 2024
1 parent 9d181d7 commit bda9075
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 30 deletions.
45 changes: 26 additions & 19 deletions MultilineGreyText/MultilineGreyTextTagger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,26 @@ public void SetSuggestion(String newSuggestion, bool inline, int caretPoint){
String line = untrim.TrimStart();
int offset = untrim.Length - line.Length;

caretPoint = Math.Max(0, caretPoint - offset);

String combineSuggestion = line + newSuggestion;
caretPoint = Math.Max(0, caretPoint - offset);

String currentText = line.Substring(0, caretPoint);
String combineSuggestion = currentText + newSuggestion;

if (line.Length - caretPoint > 0){
String currentText = line.Substring(0, caretPoint);
combineSuggestion = currentText + newSuggestion;
userEndingText = line.TrimEnd().Substring(caretPoint);
var userIndex = newSuggestion.IndexOf(userEndingText);
if(userIndex < 0){
return;

userEndingText = line.Substring(caretPoint).TrimEnd();
if (String.IsNullOrEmpty(userEndingText)){

}else{
var userIndex = newSuggestion.IndexOf(userEndingText);
if (userIndex < 0)
{
return;
}
userIndex += currentText.Length;
this.userIndex = userIndex;
}
userIndex += currentText.Length;

this.userIndex = userIndex;
isTextInsertion = true;
insertionPoint = line.Length - caretPoint;
}else{
Expand Down Expand Up @@ -455,15 +461,16 @@ public bool CompleteText(){
//replaces text in the editor
void ReplaceText(string text, int lineN){
ClearSuggestion();

SnapshotSpan span = this.snapshot.GetLineFromLineNumber(lineN).Extent;
ITextEdit edit = view.TextBuffer.CreateEdit();
if(span.Length == 0){
edit.Insert(span.Start.Position, text);
}else {
edit.Replace(span, text);
}
edit.Apply();
ITextEdit edit = view.BufferGraph.TopBuffer.CreateEdit();
var spanLength = span.Length;
edit.Replace(span, text);
var newSnapshot = edit.Apply();

if(spanLength == 0 && text.Length > 0){
view.Caret.MoveToPreviousCaretPosition();
view.Caret.MoveToNextCaretPosition();
}
}

//sets up the suggestion for display
Expand Down
28 changes: 20 additions & 8 deletions MultilineGreyText/RefactLanguageClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,12 @@ public async Task<Connection> ActivateAsync(CancellationToken token){
info.CreateNoWindow = true;

//starts the lsp process
Process process = new Process();
process.StartInfo = info;
serverProcess = new Process();
serverProcess.StartInfo = info;

if (process.Start()){
if (serverProcess.Start()){
//returns the connection for future use
this.c = new Connection(process.StandardOutput.BaseStream, process.StandardInput.BaseStream);
this.c = new Connection(serverProcess.StandardOutput.BaseStream, serverProcess.StandardInput.BaseStream);
return c;
}

Expand Down Expand Up @@ -185,7 +185,6 @@ public async Task OnLoadedAsync(){
if (StartAsync != null){
loaded = true;
await StartAsync.InvokeAsync(this, EventArgs.Empty);
statusBar = new StatusBar();
}
}

Expand Down Expand Up @@ -298,24 +297,37 @@ public async Task<string> RefactCompletion(PropertyCollection props, String file

async void ShowDefaultStatusBar(){
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
if (!statusBar.IsInitialized()){
statusBar.InitStatusBar();
}
statusBar.ShowDefaultStatusBar();
}

async void ShowStatusBarError(String error){
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
if (!statusBar.IsInitialized()){
statusBar.InitStatusBar();
}
statusBar.ShowStatusBarError(error);
}

async void ShowLoadingStatusBar(){
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
if (!statusBar.IsInitialized()){
statusBar.InitStatusBar();
}
statusBar.ShowLoadingSymbol();
}

public void Dispose(){
if(serverProcess != null){
serverProcess.Kill();
serverProcess.WaitForExit();
serverProcess.Dispose();
try{
serverProcess.Kill();
serverProcess.WaitForExit();
serverProcess.Dispose();
}catch(Exception e){
Debug.Write("Dispose" + e.ToString());
}
}
}

Expand Down
14 changes: 11 additions & 3 deletions MultilineGreyText/StatusBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,27 @@ internal class StatusBar{
Brush whiteBrush;
Brush errorBrush;
Brush transparentBrush;
bool isInitialized = false;

public StatusBar(){
stack = new StackPanel();
stack.Width = 75.0;
stack.Orientation = Orientation.Horizontal;
ShowDefaultStatusBar();
}

public bool IsInitialized(){
return isInitialized;
}

public void InitStatusBar(){
isInitialized = true;
panel = VisualTreeUtils.FindChild(Application.Current.MainWindow, childName: "StatusBarPanel") as Panel;
whiteBrush = new SolidColorBrush(Colors.White);
errorBrush = new SolidColorBrush(Colors.Red);
transparentBrush = new SolidColorBrush(Colors.Transparent);
panel.Children.Add(stack);
ShowDefaultStatusBar();
panel.Children.Insert(3, stack);
}

public void ShowDefaultStatusBar(){
stack.Children.Clear();
stack.Background = transparentBrush;
Expand Down

0 comments on commit bda9075

Please sign in to comment.