pascalabcnet/VisualPascalABCNET/IB/CodeCompletion/CodeCompletionHelpers.cs
Александр Земляк b23f9c96d0
Деактивация кнопок, связанных с Intellisense, для языков без Intellisense + разделение ILanguageInformation на два интерфейса (#3378)
* Refactor language information classes

* Implement SimpleLanguageInformation abstract class

* Move some properties to SimpleLanguageInformation

* Implement format and debug buttons disabling if Intellisense is not supported for current language

* Add Intellisense available check in FormsExtensions to deactivate menu items if needed

* Change function interfaces in VisibilityService

* Replace CodeCompletionController.CurrentParser null checks with IntellisenseAvailable method call

* Refactor IParser and BaseParser to deduplicate code

* Fix BuildTreeInSpecialMode in SPythonParser

* Add SimpleParser class for new languages without Intellisense

* Delete duplicate SetDebugButtonsEnabled function

* Add Intellisense available check in RunService when attaching debugger

* Delete inner check in SetDebugButtonsEnabled to improve architecture

* Change CurrentParser property in CodeCompletion to be CurrentLanguage

* Divide ILanguageInformation into two interfaces (creating new ILanguageIntellisenseSupport)

* Fix LanguageIntellisenseSupport initialization in BaseLanguage

* Fix RunService fictive_attach logic

* Disable Intellisense parsing for languages without Intellisense support

* Add DefaultLanguageInformation abstract class

* Add default implementation for SetSemanticConstants in BaseLanguage

* Simplify IParser interface

* Update developer guide documentation
2026-01-27 22:25:28 +03:00

101 lines
3.4 KiB
C#

// 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;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using ICSharpCode.TextEditor;
using ICSharpCode.TextEditor.Gui.CompletionWindow;
using ICSharpCode.TextEditor.Document;
namespace VisualPascalABC
{
/// <summary>
/// Класс, предназначенный для хранения последних выбранных методов в Intellisense
/// </summary>
public class CompletionDataDispatcher
{
private static Hashtable dict = new Hashtable(StringComparer.OrdinalIgnoreCase);
public static void AddLastUsedItem(ICompletionData item)
{
if (item != null && item.Text != null && item.Text.Length > 0)
dict[item.Text[0].ToString()] = item;
}
public static ICompletionData GetLastUsedItem(char ch)
{
return dict[ch.ToString()] as ICompletionData;
}
private static CodeCompletion.SymScope cur_sc;
private static Hashtable ht = new Hashtable();
public static void AddMemberBeforeDot(CodeCompletion.SymScope sc)
{
cur_sc = sc;
}
public static void BindMember(ICompletionData item)
{
if (cur_sc != null && item != null)
ht[cur_sc.GetFullName()] = item.Text;
cur_sc = null;
}
public static string GetRecentUsedMember(CodeCompletion.SymScope sc)
{
return ht[sc.GetFullName()] as string;
}
}
public class KeywordChecker
{
public static PascalABCCompiler.Parsers.KeywordKind TestForKeyword(string Text, int i)
{
if (CodeCompletion.CodeCompletionController.IntellisenseAvailable())
return CodeCompletion.CodeCompletionController.CurrentLanguage.LanguageIntellisenseSupport.TestForKeyword(Text, i);
return PascalABCCompiler.Parsers.KeywordKind.None;
}
}
/// <summary>
/// Класс-диспетчер, прицепляющий документацию к методам и классам.
/// Документация прицепляется в отдельном потоке
/// </summary>
public class DefaultDispatcher : CodeCompletion.AbstractDispatcher
{
private Dictionary<PascalABCCompiler.Parsers.SymInfo, ICompletionData> dict = new Dictionary<PascalABCCompiler.Parsers.SymInfo, ICompletionData>();
private Dictionary<string, ICompletionData> dict2 = new Dictionary<string, ICompletionData>();
public void Reset()
{
dict.Clear();
dict2.Clear();
}
public void Add(PascalABCCompiler.Parsers.SymInfo si, ICompletionData data)
{
if (!dict.ContainsKey(si))
dict[si] = data;
if (!string.IsNullOrEmpty(si.description) && !dict2.ContainsKey(si.description))
dict2[si.description] = data;
}
public override void Update(PascalABCCompiler.Parsers.SymInfo si)
{
ICompletionData val=null;
if (dict.TryGetValue(si,out val))
{
val.Description = si.description;
}
else if (si.description != null && dict2.TryGetValue(si.description.Split('\n')[0], out val))
{
val.Description = si.description;
}
}
}
}