2022-06-30 09:47:11 +03:00
|
|
|
|
// Copyright (c) Ivan Bondarev, Stanislav Mikhalkovich (for details please see \doc\copyright.txt)
|
|
|
|
|
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
|
|
using ICSharpCode.TextEditor;
|
|
|
|
|
|
|
|
|
|
|
|
namespace VisualPascalABC
|
|
|
|
|
|
{
|
|
|
|
|
|
class DefaultInsightDataProvider : ICSharpCode.TextEditor.Gui.InsightWindow.IInsightDataProvider
|
|
|
|
|
|
{
|
|
|
|
|
|
private string fileName = null;
|
|
|
|
|
|
private ICSharpCode.TextEditor.Document.IDocument document = null;
|
|
|
|
|
|
private TextArea textArea = null;
|
|
|
|
|
|
private string[] methods; //= new List<CodeCompletion.ProcScope>();
|
|
|
|
|
|
private int lookupOffset;
|
|
|
|
|
|
private bool setupOnlyOnce;
|
|
|
|
|
|
private int initialOffset;
|
|
|
|
|
|
private char pressed_key;
|
|
|
|
|
|
public int defaultIndex = 0;
|
|
|
|
|
|
public int num_param = 1;
|
|
|
|
|
|
public int cur_param_num = 1;
|
|
|
|
|
|
public int param_count;
|
|
|
|
|
|
|
|
|
|
|
|
public DefaultInsightDataProvider(int lookupOffset, bool setupOnlyOnce, char pressed_key)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.lookupOffset = lookupOffset;
|
|
|
|
|
|
this.setupOnlyOnce = setupOnlyOnce;
|
|
|
|
|
|
this.pressed_key = pressed_key;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private string FindExpression(int off, string Text, int line, int col)
|
|
|
|
|
|
{
|
2026-01-27 22:25:28 +03:00
|
|
|
|
if (CodeCompletion.CodeCompletionController.IntellisenseAvailable())
|
|
|
|
|
|
return CodeCompletion.CodeCompletionController.CurrentLanguage.LanguageIntellisenseSupport.FindExpressionForMethod(off, Text, line, col, pressed_key, ref num_param);
|
2022-06-30 09:47:11 +03:00
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void SetupDataProvider(string fileName, TextArea textArea)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
if (setupOnlyOnce && this.textArea != null)
|
|
|
|
|
|
{
|
2026-01-27 22:25:28 +03:00
|
|
|
|
if (CodeCompletion.CodeCompletionController.CurrentLanguage.LanguageIntellisenseSupport.IsMethodCallParameterSeparator(pressed_key))
|
2022-06-30 09:47:11 +03:00
|
|
|
|
{
|
|
|
|
|
|
FindExpression(textArea.Caret.Offset, textArea.Document.TextContent.Substring(0, textArea.Caret.Offset),
|
|
|
|
|
|
textArea.Caret.Line, textArea.Caret.Column);
|
|
|
|
|
|
num_param++;
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
else return;
|
|
|
|
|
|
}
|
|
|
|
|
|
this.fileName = fileName;
|
|
|
|
|
|
this.textArea = textArea;
|
|
|
|
|
|
this.document = textArea.Document;
|
|
|
|
|
|
int useOffset = (lookupOffset < 0) ? textArea.Caret.Offset : lookupOffset;
|
|
|
|
|
|
initialOffset = useOffset;
|
|
|
|
|
|
int i = initialOffset - 1;
|
|
|
|
|
|
int off = textArea.Caret.Offset;
|
|
|
|
|
|
string Text = textArea.Document.TextContent.Substring(0, textArea.Caret.Offset);
|
|
|
|
|
|
int line = textArea.Caret.Line;
|
|
|
|
|
|
int col = textArea.Caret.Column;
|
|
|
|
|
|
|
|
|
|
|
|
string expr = FindExpression(off, Text, line, col);
|
|
|
|
|
|
List<PascalABCCompiler.Errors.Error> Errors = new List<PascalABCCompiler.Errors.Error>();
|
2024-05-25 12:26:32 +03:00
|
|
|
|
PascalABCCompiler.SyntaxTree.expression e = Languages.Facade.LanguageProvider.Instance.SelectLanguageByExtensionSafe(fileName)?.Parser.GetExpression("test.pas", expr, Errors, new List<PascalABCCompiler.Errors.CompilerWarning>());
|
2022-06-30 09:47:11 +03:00
|
|
|
|
if (e == null || Errors.Count > 0) return;
|
|
|
|
|
|
CodeCompletion.DomConverter dconv = (CodeCompletion.DomConverter)CodeCompletion.CodeCompletionController.comp_modules[fileName];
|
|
|
|
|
|
string fname = fileName;
|
|
|
|
|
|
if (dconv != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
//if (pressed_key == '(' || pressed_key == ',')
|
2026-01-27 22:25:28 +03:00
|
|
|
|
if (CodeCompletion.CodeCompletionController.CurrentLanguage.LanguageIntellisenseSupport.IsOpenBracketForMethodCall(pressed_key) || CodeCompletion.CodeCompletionController.CurrentLanguage.LanguageIntellisenseSupport.IsMethodCallParameterSeparator(pressed_key))
|
2022-06-30 09:47:11 +03:00
|
|
|
|
methods = dconv.GetNameOfMethod(e, expr, line, col, num_param, ref defaultIndex, cur_param_num, out param_count);
|
2026-01-27 22:25:28 +03:00
|
|
|
|
else if (CodeCompletion.CodeCompletionController.CurrentLanguage.LanguageIntellisenseSupport.IsOpenBracketForIndex(pressed_key))
|
2022-06-30 09:47:11 +03:00
|
|
|
|
methods = dconv.GetIndex(e, line, col);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool CaretOffsetChanged()
|
|
|
|
|
|
{
|
|
|
|
|
|
bool closeDataProvider = textArea.Caret.Offset <= initialOffset;
|
|
|
|
|
|
int brackets = 0;
|
|
|
|
|
|
if (!closeDataProvider)
|
|
|
|
|
|
{
|
|
|
|
|
|
bool insideChar = false;
|
|
|
|
|
|
bool insideString = false;
|
|
|
|
|
|
for (int offset = initialOffset; offset < Math.Min(textArea.Caret.Offset, document.TextLength); ++offset)
|
|
|
|
|
|
{
|
|
|
|
|
|
char ch = document.GetCharAt(offset);
|
|
|
|
|
|
switch (ch)
|
|
|
|
|
|
{
|
|
|
|
|
|
case '\'':
|
|
|
|
|
|
insideChar = !insideChar;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case '[':
|
|
|
|
|
|
if (!(insideChar || insideString))
|
|
|
|
|
|
{
|
|
|
|
|
|
++brackets;
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case ']':
|
|
|
|
|
|
if (!(insideChar || insideString))
|
|
|
|
|
|
{
|
|
|
|
|
|
--brackets;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (brackets <= 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case '(':
|
|
|
|
|
|
if (!(insideChar || insideString))
|
|
|
|
|
|
{
|
|
|
|
|
|
++brackets;
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case ')':
|
|
|
|
|
|
if (!(insideChar || insideString))
|
|
|
|
|
|
{
|
|
|
|
|
|
--brackets;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (brackets <= 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case ';':
|
|
|
|
|
|
if (!(insideChar || insideString))
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return closeDataProvider;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public string GetInsightData(int number)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (number >= methods.Length)
|
|
|
|
|
|
number = methods.Length - 1;
|
|
|
|
|
|
return methods[number];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public int InsightDataCount
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
if (methods != null)
|
|
|
|
|
|
return methods.Length;
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public int DefaultIndex
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return Math.Min(defaultIndex, InsightDataCount-1);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|