From 0626885b5fac8d15f618d14d97cb2bbbe94fa774 Mon Sep 17 00:00:00 2001 From: AlexanderZemlyak <92867056+AlexanderZemlyak@users.noreply.github.com> Date: Wed, 1 Oct 2025 11:47:05 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=B8=D0=BD=D0=B3=20=D0=B2=20Intellisense=20(#3328)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Migrate from HashTable to Dictionary (StandartDirectories variable) * Add check to register files for parsing only if they have supported extension * Delete legacy code in CodeCompletion.cs * Delete unnecessary fields in CodeCompletionController * Refactor compiling dependencies code in DomSyntaxTreeVisitor * Fix AddStandardNetNamespacesToUserScope check * Comment out uses *some type* support in Intellisense * Delete unused SemanticOptions in DomSyntaxTreeVisitor * Comment out unused NamespaceTypeScope --- CodeCompletion/CodeCompletion.cs | 257 ++++--------- CodeCompletion/DomSyntaxTreeVisitor.cs | 350 +++++++----------- CodeCompletion/SymTable.cs | 4 +- Compiler/Compiler.cs | 4 +- CompilerTools/Tools.cs | 4 +- NETGenerator/CodeGenerator.cs | 5 +- NETGenerator/NETGenerator.cs | 4 +- .../DS/VisualEnvironmentCompiler.cs | 4 +- .../CodeFileDocumentTextEditorControl.cs | 3 +- VisualPascalABCNET/Form1.cs | 9 +- .../CodeCompletionParserController.cs | 40 +- .../CodeCompletion/CodeCompletionProvider.cs | 2 +- VisualPascalABCNET/Workbench/BuildService.cs | 6 +- .../Workbench/WorkbenchServiceFactory.cs | 2 +- .../DS/VisualEnvironmentCompiler.cs | 4 +- .../CodeFileDocumentTextEditorControl.cs | 13 +- VisualPascalABCNETLinux/Form1.cs | 9 +- .../CodeCompletionParserController.cs | 40 +- .../CodeCompletion/CodeCompletionProvider.cs | 2 +- .../Workbench/BuildService.cs | 6 +- .../Workbench/WorkbenchServiceFactory.cs | 2 +- bin/Lib/SPythonSystem.pas | 9 +- 22 files changed, 296 insertions(+), 483 deletions(-) diff --git a/CodeCompletion/CodeCompletion.cs b/CodeCompletion/CodeCompletion.cs index 990485154..140dcfd25 100644 --- a/CodeCompletion/CodeCompletion.cs +++ b/CodeCompletion/CodeCompletion.cs @@ -9,15 +9,13 @@ using PascalABCCompiler.Parsers; using PascalABCCompiler.Errors; using System.IO; using Languages.Facade; -//using ICSharpCode.SharpDevelop.Dom; namespace CodeCompletion { public class CodeCompletionController { - public static LanguageProvider LanguageProvider = LanguageProvider.Instance; - private string FileName; - string Text; + private static readonly LanguageProvider LanguageProvider = LanguageProvider.Instance; + public Dictionary docs = new Dictionary(); // static bool parsers_loaded=false; public IParser Parser; @@ -39,7 +37,7 @@ namespace CodeCompletion } public static PascalABCCompiler.Compiler comp;// = new PascalABCCompiler.Compiler(); - public static Hashtable StandartDirectories = new Hashtable(); + public static Dictionary StandartDirectories = new Dictionary(); public static Hashtable comp_modules = new Hashtable(StringComparer.OrdinalIgnoreCase); // public static Hashtable parsers = new Hashtable(StringComparer.OrdinalIgnoreCase); public static Dictionary pabcNamespaces = new Dictionary(); @@ -67,50 +65,26 @@ namespace CodeCompletion return currentLanguage?.Parser; } } - - internal compilation_unit ParsersControllerGetCompilationUnit(string FileName, string Text, List ErrorsList, List Warnings, bool compilingNotMainProgram) - { - ILanguage language = LanguageProvider.SelectLanguageByExtensionSafe(FileName); - if (language == null) - return null; - Parser = language.Parser; - - return Parser.GetCompilationUnit(FileName, Text, ErrorsList, Warnings, ParseMode.Normal, compilingNotMainProgram); - } - - internal compilation_unit ParsersControllerGetCompilationUnitSpecial(string FileName, string Text, List ErrorsList, List Warnings, bool compilingNotMainProgram) - { - ILanguage language = LanguageProvider.SelectLanguageByExtensionSafe(FileName); - if (language == null) - return null; - - return Parser.GetCompilationUnit(FileName, Text, ErrorsList, Warnings, ParseMode.Special, compilingNotMainProgram); - } public DomConverter Compile(string FileName, string Text) { - this.Text = Text; - this.FileName = FileName; - List ErrorsList = new List(); + List ErrorsList = new List(); List Warnings = new List(); - PascalABCCompiler.SyntaxTree.compilation_unit cu = null; - IDocParser docParser = null; - string ext = Path.GetExtension(FileName); + compilation_unit cu = null; + + ILanguage currentLanguage = LanguageProvider.SelectLanguageByExtension(FileName); + + Parser = currentLanguage.Parser; + try { - cu = ParsersControllerGetCompilationUnit(FileName, Text, ErrorsList, Warnings, false); + cu = Parser.GetCompilationUnit(FileName, Text, ErrorsList, Warnings, ParseMode.Normal, false); + ErrorsList.Clear(); - docParser = LanguageProvider.SelectLanguageByExtension(FileName).DocParser; + if (currentLanguage.DocParser != null) + BuildDocs(Text, cu, currentLanguage.DocParser); - if (docParser != null) - { - documentation_comment_list dt = docParser.BuildTree(Text); - PascalABCCompiler.DocumentationConstructor docconst = new PascalABCCompiler.DocumentationConstructor(); - if (cu != null) - docs = docconst.Construct(cu, dt); - } - } catch (Exception e) { @@ -131,32 +105,26 @@ namespace CodeCompletion dconv.ConvertToDom(cu); } - else + // Попытка поменять текст программы ниже сработает только для PascalABC.NET + else if (currentLanguage == LanguageProvider.MainLanguage) { + ErrorsList.Clear(); Warnings.Clear(); try { - //cu = ParsersController.GetComilationUnit(file_name, Text+")))));end.",comp.CompilerOptions.ParserSearchPatchs,ErrorsList); - //cu = ParsersControllerGetComilationUnit(file_name, get_temp_text(Text), ErrorsList, true); string tmp = ParsersHelper.GetModifiedProgramm(Text); if (tmp != null) { - cu = ParsersControllerGetCompilationUnitSpecial(FileName, tmp, ErrorsList, Warnings, false); - } - if (comp_modules[FileName] == null) - { - if (cu == null) - cu = get_fictive_unit(Text, FileName); + cu = Parser.GetCompilationUnit(FileName, Text, ErrorsList, Warnings, ParseMode.Special, false); } + ErrorsList.Clear(); - if (docParser != null) - { - documentation_comment_list dt = docParser.BuildTree(Text); - PascalABCCompiler.DocumentationConstructor docconst = new PascalABCCompiler.DocumentationConstructor(); - if (cu != null) - docs = docconst.Construct(cu, dt); - } + Warnings.Clear(); + + if (currentLanguage.DocParser != null) + BuildDocs(Text, cu, currentLanguage.DocParser); + } catch (Exception e) { @@ -176,177 +144,88 @@ namespace CodeCompletion //ConvertToDom(cu); } - //vremenno, potom ubrat - private compilation_unit get_fictive_unit(string s, string FileName) + private void BuildDocs(string Text, compilation_unit cu, IDocParser docParser) { - program_module prog = new program_module(); - int line = 1; - int col = 1; - for (int i = 0; i < s.Length; i++) - if (s[i] == '\n') - { - line++; - col = 1; - } - else - { - col++; - } - prog.source_context = new SourceContext(1, 1, line + 3, 3); - prog.program_block = new block(); - prog.file_name = FileName; - statement_list sl = new statement_list(); - prog.program_block.program_code = sl; - prog.program_block.program_code.left_logical_bracket = new token_info("begin"); - prog.program_block.program_code.left_logical_bracket.source_context = new SourceContext(1, 1, 1, 5); - prog.program_block.program_code.right_logical_bracket = new token_info("end"); - prog.program_block.program_code.right_logical_bracket.source_context = new SourceContext(line + 3, 1, line + 3, 3); - sl.subnodes.Add(new empty_statement()); - return prog; - } - - public PascalABCCompiler.SyntaxTree.compilation_unit ParseOnlySyntaxTree(string FileName, string Text) - { - List ErrorsList = new List(); - List Warnings = new List(); - PascalABCCompiler.SyntaxTree.compilation_unit cu = ParsersControllerGetCompilationUnit(FileName, Text, ErrorsList, Warnings, false); - return cu; - } - - /*public DomConverter CompileAllIfNeed(string FileName, string Text) - { - DomConverter dconv = (DomConverter)comp_modules[FileName]; - if (dconv != null) return dconv; - this.Text = Text; - this.FileName = FileName; - string ext = Path.GetExtension(FileName); - List ErrorsList = new List(); - List Warnings = new List(); - ILanguage language = LanguageProvider.SelectLanguageByExtensionSafe(FileName); - if (language == null) - return dconv; - Parser = language.Parser; - compilation_unit cu = language.Parser.GetCompilationUnit(FileName, Text, ErrorsList, Warnings, ParseMode.Normal); - ErrorsList.Clear(); - documentation_comment_list dt = language.DocParser.BuildTree(Text); + documentation_comment_list dt = docParser.BuildTree(Text); PascalABCCompiler.DocumentationConstructor docconst = new PascalABCCompiler.DocumentationConstructor(); if (cu != null) docs = docconst.Construct(cu, dt); - dconv = new DomConverter(this); - if (CodeCompletionTools.XmlDoc.LookupLocalizedXmlDocForUnitWithSources(FileName, CodeCompletionController.currentLanguageISO) != null) - { - dconv.visitor.add_doc_from_text = false; - } - if (cu != null) - dconv.ConvertToDom(cu); - else - { - ErrorsList.Clear(); - Warnings.Clear(); - //cu = ParsersControllerGetComilationUnit(file_name, Text, ErrorsList, true); - if (comp_modules[FileName] == null) - { - string tmp = ParsersHelper.GetModifiedProgramm(Text); - if (tmp != null) - { - cu = ParsersControllerGetCompilationUnitSpecial(FileName, tmp, ErrorsList, Warnings); - ErrorsList.Clear(); - } - if (cu == null) - cu = get_fictive_unit(Text, FileName); - } - ErrorsList.Clear(); - Warnings.Clear(); - dt = language.DocParser.BuildTree(Text); - //PascalABCCompiler.DocumentationConstructor docconst = new PascalABCCompiler.DocumentationConstructor(); - if (cu != null) - docs = docconst.Construct(cu, dt); - if (CodeCompletionTools.XmlDoc.LookupLocalizedXmlDocForUnitWithSources(FileName, CodeCompletionController.currentLanguageISO) != null) - { - dconv.visitor.add_doc_from_text = false; - } - if (cu != null) - { - dconv.ConvertToDom(cu); - } - } - //comp_modules[file_name] = dconv; - if (dconv.is_compiled) comp_modules[FileName] = dconv; - - if (docs != null) docs.Clear(); - //GC.Collect(); - return dconv; - }*/ + } + + public compilation_unit ParseOnlySyntaxTree(string FileName, string Text) + { + var currentLanguage = LanguageProvider.SelectLanguageByExtensionSafe(FileName); + + if (currentLanguage == null) + return null; + + var cu = currentLanguage.Parser.GetCompilationUnit(FileName, Text, new List(), new List(), ParseMode.Normal, false); + + return cu; + } public DomConverter CompileAllIfNeed(string FileName, bool parse_only_interface=false) { - this.FileName = FileName; - this.Text = comp.GetSourceFileText(FileName); - string ext = Path.GetExtension(FileName); - List ErrorsList = new List(); + string Text = comp.GetSourceFileText(FileName); + List ErrorsList = new List(); List Warnings = new List(); - PascalABCCompiler.SyntaxTree.compilation_unit cu = null; + compilation_unit cu = null; DomConverter dconv = new DomConverter(this); - ILanguage language = LanguageProvider.SelectLanguageByExtensionSafe(FileName); - if (language == null) + ILanguage currentLanguage = LanguageProvider.SelectLanguageByExtensionSafe(FileName); + + if (currentLanguage == null) return dconv; - Parser = language.Parser; + + Parser = currentLanguage.Parser; + if (Text != null) { - cu = language.Parser.GetCompilationUnit(FileName, Text, ErrorsList, Warnings, ParseMode.Normal, true); + cu = Parser.GetCompilationUnit(FileName, Text, ErrorsList, Warnings, ParseMode.Normal, true); } ErrorsList.Clear(); Warnings.Clear(); - var docParser = language.DocParser; - - if (docParser != null) - { - documentation_comment_list dt = docParser.BuildTree(Text); - PascalABCCompiler.DocumentationConstructor docconst = new PascalABCCompiler.DocumentationConstructor(); - if (cu != null) - docs = docconst.Construct(cu, dt); - } + if (currentLanguage.DocParser != null) + BuildDocs(Text, cu, currentLanguage.DocParser); dconv.visitor.parse_only_interface = parse_only_interface; if (CodeCompletionTools.XmlDoc.LookupLocalizedXmlDocForUnitWithSources(FileName, CodeCompletionController.currentLanguageISO) != null) { dconv.visitor.add_doc_from_text = false; } + if (cu != null) + { dconv.ConvertToDom(cu); - else + } + // Попытка поменять текст программы ниже сработает только для PascalABC.NET + else if (currentLanguage == LanguageProvider.MainLanguage) { ErrorsList.Clear(); Warnings.Clear(); - //cu = ParsersControllerGetComilationUnit(file_name, Text, ErrorsList, true); + if (comp_modules[FileName] == null) { string tmp = ParsersHelper.GetModifiedProgramm(Text); if (tmp != null) { - cu = ParsersControllerGetCompilationUnitSpecial(FileName, tmp, ErrorsList, Warnings, true); - ErrorsList.Clear(); + cu = Parser.GetCompilationUnit(FileName, Text, ErrorsList, Warnings, ParseMode.Special, true); } - if (cu == null) - cu = get_fictive_unit(Text, FileName); - } - ErrorsList.Clear(); - Warnings.Clear(); - if (docParser != null) - { - documentation_comment_list dt = docParser.BuildTree(Text); - PascalABCCompiler.DocumentationConstructor docconst = new PascalABCCompiler.DocumentationConstructor(); - if (cu != null) - docs = docconst.Construct(cu, dt); + ErrorsList.Clear(); + Warnings.Clear(); } + + if (currentLanguage.DocParser != null) + BuildDocs(Text, cu, currentLanguage.DocParser); + if (CodeCompletionTools.XmlDoc.LookupLocalizedXmlDocForUnitWithSources(FileName, CodeCompletionController.currentLanguageISO) != null) { - dconv.visitor.add_doc_from_text = false; + dconv.visitor.add_doc_from_text = false; } + if (cu != null) { dconv.ConvertToDom(cu); @@ -409,8 +288,8 @@ namespace CodeCompletion if (CodeCompletionController.comp != null) Dirs.AddRange(CodeCompletionController.comp.CompilerOptions.SearchDirectories); // Надо как-то проверять, что мы не в инсталированной версии EVA - if (CodeCompletionController.StandartDirectories.ContainsKey(LibSourceDirectoryIdent) && Directory.Exists((string)CodeCompletionController.StandartDirectories[LibSourceDirectoryIdent])) - Dirs.Add((string)CodeCompletionController.StandartDirectories[LibSourceDirectoryIdent]); + if (CodeCompletionController.StandartDirectories.ContainsKey(LibSourceDirectoryIdent) && Directory.Exists(CodeCompletionController.StandartDirectories[LibSourceDirectoryIdent])) + Dirs.Add(CodeCompletionController.StandartDirectories[LibSourceDirectoryIdent]); return CodeCompletionController.comp.FindSourceFileNameInDirs(unit_name, out found_dir_ind, caseSensitiveSearch, Dirs.ToArray()); } diff --git a/CodeCompletion/DomSyntaxTreeVisitor.cs b/CodeCompletion/DomSyntaxTreeVisitor.cs index 3961059ae..5ba79fdb2 100644 --- a/CodeCompletion/DomSyntaxTreeVisitor.cs +++ b/CodeCompletion/DomSyntaxTreeVisitor.cs @@ -15,10 +15,6 @@ using System.Text; namespace CodeCompletion { - public class SemanticOptions - { - public bool allow_import_types=true; - } public class DomSyntaxTreeVisitor : AbstractVisitor { @@ -44,7 +40,6 @@ namespace CodeCompletion private static Compiler compiler; public static bool use_semantic_for_intellisense; private Dictionary method_call_cache = new Dictionary(); - public SemanticOptions semantic_options = new SemanticOptions(); public Hashtable cur_used_assemblies; public DomSyntaxTreeVisitor(DomConverter converter) @@ -2514,7 +2509,17 @@ namespace CodeCompletion AssemblyDocCache.Load(_as, path); PascalABCCompiler.NetHelper.NetHelper.init_namespaces(_as); List namespaces = new List(); - namespaces.AddRange(PascalABCCompiler.NetHelper.NetHelper.GetNamespaces(_as)); + + currentUnitLanguage = Languages.Facade.LanguageProvider.Instance.SelectLanguageByExtension(_unit_module.file_name); + + string unitName = _unit_module.unit_name.idunit_name.name; + + var languageUsingStandardUnit = Languages.Facade.LanguageProvider.Instance.Languages.Find(lang => lang.SystemUnitNames.Contains(unitName)); + + // Пока что добавили возможость грубо отключить добавление NET пространств имен по умолчанию здесь (второе условие нужно, чтобы в стандартные модули языка они тоже не добавлялись) EVA + if (currentUnitLanguage.LanguageInformation.AddStandardNetNamespacesToUserScope && (languageUsingStandardUnit?.LanguageInformation.AddStandardNetNamespacesToUserScope ?? true)) + namespaces.AddRange(PascalABCCompiler.NetHelper.NetHelper.GetNamespaces(_as)); + InterfaceUnitScope unit_scope = null; bool existed_ns = false; is_namespace = _unit_module.unit_name.HeaderKeyword == UnitHeaderKeyword.Namespace; @@ -2638,8 +2643,6 @@ namespace CodeCompletion } } - string unitName = _unit_module.unit_name.idunit_name.name; - // считаем основной модуль идущим первым в списке EVA var language = Languages.Facade.LanguageProvider.Instance.Languages.Find(lang => lang.SystemUnitNames.First() == unitName); @@ -2657,23 +2660,15 @@ namespace CodeCompletion CodeCompletionController.comp_modules[_unit_module.file_name] = this.converter; - currentUnitLanguage = Languages.Facade.LanguageProvider.Instance.SelectLanguageByExtension(_unit_module.file_name); - - var languageUsingStandardUnit = Languages.Facade.LanguageProvider.Instance.Languages.Find(lang => lang.SystemUnitNames.Contains(unitName)); - if (!existed_ns) { - // Пока что добавили возможость грубо отключить добавление NET пространств имен по умолчанию здесь (второе условие нужно, чтобы в стандартные модули языка они тоже не добавлялись) EVA - if (currentUnitLanguage.LanguageInformation.AddStandardNetNamespacesToUserScope && (languageUsingStandardUnit?.LanguageInformation.AddStandardNetNamespacesToUserScope ?? true)) + foreach (string s in namespaces) { - foreach (string s in namespaces) + if (!ns_cache.ContainsKey(s)) { - if (!ns_cache.ContainsKey(s)) - { - NamespaceScope ns_scope = new NamespaceScope(s); - entry_scope.AddName(s, ns_scope); - ns_cache[s] = s; - } + NamespaceScope ns_scope = new NamespaceScope(s); + entry_scope.AddName(s, ns_scope); + ns_cache[s] = s; } } } @@ -2692,17 +2687,16 @@ namespace CodeCompletion if (_interface_node.uses_modules != null) { - (cur_scope as InterfaceUnitScope).uses_source_range = get_location(_interface_node.uses_modules); - usedUnitsNames = _interface_node.uses_modules.units.Select(unit => unit.name.idents[0].name).ToList(); - //foreach (unit_or_namespace s in _interface_node.uses_modules.units) + (cur_scope as InterfaceUnitScope).uses_source_range = get_location(_interface_node.uses_modules); + + // компиляция зависимостей из секции uses for (int j = _interface_node.uses_modules.units.Count - 1; j >= 0; j--) { unit_or_namespace s = _interface_node.uses_modules.units[j]; - add_unit_ref(s, Path.GetDirectoryName(_unit_module.file_name), - cur_scope, ns_cache, semantic_options.allow_import_types, - unl, currentUnitLanguage.CaseSensitive); + CompileUsedUnitOrNamespace(s, Path.GetDirectoryName(_unit_module.file_name), + cur_scope, ns_cache, unl, currentUnitLanguage.CaseSensitive); } } @@ -2897,22 +2891,9 @@ namespace CodeCompletion } } } - - /* - private void add_system_unit() - { - AddUnit(this.converter.controller.Parser?.LanguageInformation.SystemUnitName); - } - private void add_extensions_unit() - { - AddUnit(StringConstants.pascalExtensionsUnitName); - } - */ - - private void add_unit_ref(unit_or_namespace s, string curr_path, - SymScope cur_scope, Hashtable ns_cache, bool allow_import_types, - using_namespace_list unl, bool caseSensitiveSearch) + private void CompileUsedUnitOrNamespace(unit_or_namespace s, string curr_path, + SymScope cur_scope, Hashtable ns_cache, using_namespace_list unl, bool caseSensitiveSearch) { try @@ -2920,105 +2901,76 @@ namespace CodeCompletion if (s is uses_unit_in uui) { string unit_name = CodeCompletionNameHelper.FindSourceFileName(uui.in_file.Value, out _, caseSensitiveSearch, curr_path); - if (unit_name==null) throw new InvalidOperationException($"uses '{uui.in_file.Value}';"); - - DomConverter dc = CodeCompletionController.comp_modules[unit_name] as DomConverter; - if (dc == null /*|| CodeCompletionController.recomp_files[unit_name] != null*/) - { - dc = new CodeCompletionController().CompileAllIfNeed(unit_name, true); - } - if (dc.visitor != null) - { - dc.visitor.entry_scope.InitAssemblies(); - cur_scope.AddUsedUnit(dc.visitor.entry_scope); - cur_scope.AddName(Path.GetFileNameWithoutExtension(unit_name), dc.visitor.entry_scope); - } - + if (unit_name == null) throw new InvalidOperationException($"uses '{uui.in_file.Value}';"); + + CompileUnit(unit_name, cur_scope); } else { - string str = ""; - for (int i = 0; i < s.name.idents.Count; i++) + string usedName = ""; + + if (s.name.idents.Count == 1) { - str += s.name.idents[i].name; + usedName = s.name.idents[0].name; - string realName = str; + // на случай имен модулей, отличающихся от имен файла EVA + string realName = GetRealNameForModule(usedName); - if (s.name.idents.Count == 1) + string pcu_unit_name = FindPCUFileName(realName, curr_path, caseSensitiveSearch); + string unit_name = CodeCompletionNameHelper.FindSourceFileName(realName, out _, caseSensitiveSearch, curr_path); + + /*if (pcu_unit_name != null && unit_name != null && string.Compare(System.IO.Path.GetDirectoryName(_program_module.file_name), System.IO.Path.GetDirectoryName(pcu_unit_name), true) == 0 + && string.Compare(System.IO.Path.GetDirectoryName(_program_module.file_name), System.IO.Path.GetDirectoryName(unit_name), true) != 0) + unit_name = null;*/ + if (unit_name != null) { - // на случай имен модулей, отличающихся от имен файла EVA - realName = GetRealNameForModule(str); + CompileUnit(unit_name, cur_scope); } - - NamespaceScope ns_scope = null; - if (i == 0) + else { - string pcu_unit_name = FindPCUFileName(realName, curr_path, caseSensitiveSearch); - string unit_name = CodeCompletionNameHelper.FindSourceFileName(realName, out _, caseSensitiveSearch, curr_path); - - /*if (pcu_unit_name != null && unit_name != null && string.Compare(System.IO.Path.GetDirectoryName(_program_module.file_name), System.IO.Path.GetDirectoryName(pcu_unit_name), true) == 0 - && string.Compare(System.IO.Path.GetDirectoryName(_program_module.file_name), System.IO.Path.GetDirectoryName(unit_name), true) != 0) - unit_name = null;*/ + unit_name = pcu_unit_name; + if (unit_name != null) { - DomConverter dc = CodeCompletionController.comp_modules[unit_name] as DomConverter; - if (dc == null /*|| CodeCompletionController.recomp_files[unit_name] != null*/) - { - dc = new CodeCompletionController().CompileAllIfNeed(unit_name, true); - } - if (dc.visitor != null) - { - dc.visitor.entry_scope.InitAssemblies(); - cur_scope.AddUsedUnit(dc.visitor.entry_scope); - cur_scope.AddName(str, dc.visitor.entry_scope); - } + IntellisensePCUReader pcu_rdr = new IntellisensePCUReader(); + SymScope ss = pcu_rdr.GetUnit(unit_name); + UnitDocCache.Load(ss, unit_name); + cur_scope.AddUsedUnit(ss); + cur_scope.AddName(usedName, ss); } else { - //unit_name = FindPCUFileName(str); - unit_name = pcu_unit_name; - if (unit_name != null) + // У пространств имен Паскаля может быть разделение по точке, но этот случай не учитывается в ветке else EVA + if (CodeCompletionController.pabcNamespaces.ContainsKey(usedName.ToLower())) { - IntellisensePCUReader pcu_rdr = new IntellisensePCUReader(); - SymScope ss = pcu_rdr.GetUnit(unit_name); - UnitDocCache.Load(ss, unit_name); - cur_scope.AddUsedUnit(ss); - cur_scope.AddName(str, ss); + InterfaceUnitScope un_scope = CodeCompletionController.pabcNamespaces[usedName.ToLower()]; + cur_scope.AddUsedUnit(un_scope); + cur_scope.AddName(usedName, un_scope); } - else + else if (PascalABCCompiler.NetHelper.NetHelper.IsNetNamespace(usedName)) { - if (CodeCompletion.CodeCompletionController.pabcNamespaces.ContainsKey(str.ToLower())) - { - InterfaceUnitScope un_scope = CodeCompletion.CodeCompletionController.pabcNamespaces[str.ToLower()]; - cur_scope.AddUsedUnit(un_scope); - cur_scope.AddName(str, un_scope); - } - else if (PascalABCCompiler.NetHelper.NetHelper.IsNetNamespace(str)) - { - ns_scope = new NamespaceScope(str); - ns_cache[str] = str; - cur_scope.AddName(str, ns_scope); - if (s.name.idents.Count == 1) - cur_scope.AddUsedUnit(ns_scope); - } - else if (PascalABCCompiler.NetHelper.NetHelper.IsType(str) && allow_import_types) - { - Type t = PascalABCCompiler.NetHelper.NetHelper.FindType(str); - cur_scope.AddUsedUnit(new NamespaceTypeScope(TypeTable.get_compiled_type(new SymInfo(t.Name, SymbolKind.Class, t.FullName), t))); - } - + var ns_scope = new NamespaceScope(usedName); + ns_cache[usedName] = usedName; + cur_scope.AddName(usedName, ns_scope); + cur_scope.AddUsedUnit(ns_scope); } - //unit_name = System.IO.Path.GetDirectoryName(_program_module.file_name)+"\\"+str+System.IO.Path.GetExtension(_program_module.file_name); + // Не поддерживается в основном компиляторе EVA + /*else if (PascalABCCompiler.NetHelper.NetHelper.IsType(usedName) && allow_import_types) + { + Type t = PascalABCCompiler.NetHelper.NetHelper.FindType(usedName); + cur_scope.AddUsedUnit(new NamespaceTypeScope(TypeTable.get_compiled_type(new SymInfo(t.Name, SymbolKind.Class, t.FullName), t))); + }*/ } } - if (i == s.name.idents.Count - 1 && i > 0 /*&& PascalABCCompiler.NetHelper.NetHelper.IsNetNamespace(str)*/) - //possible_namespaces.Add(str); - cur_scope.AddUsedUnit(new NamespaceScope(str)); - if (i < s.name.idents.Count - 1) - str += "."; - } - unl.AddElement(new PascalABCCompiler.TreeRealization.using_namespace(str)); + else + { + usedName = string.Join(".", s.name.idents.Select(id => id.name)); + + cur_scope.AddUsedUnit(new NamespaceScope(usedName)); + } + + unl.AddElement(new using_namespace(usedName)); } } catch (Exception e) @@ -3029,9 +2981,22 @@ namespace CodeCompletion } } + private void CompileUnit(string unit_name, SymScope cur_scope) + { + var dc = (DomConverter)CodeCompletionController.comp_modules[unit_name] + ?? new CodeCompletionController().CompileAllIfNeed(unit_name, true); + + if (dc.visitor != null) + { + dc.visitor.entry_scope.InitAssemblies(); + cur_scope.AddUsedUnit(dc.visitor.entry_scope); + cur_scope.AddName(Path.GetFileNameWithoutExtension(unit_name), dc.visitor.entry_scope); + } + } + private string GetRealNameForModule(string nameInUses) { - // для такого пока не реализована поддержка EVA + // для такого пока не реализована поддержка в конверторах синтаксического дерева EVA /*var specialModulesAliases = Languages.Facade.LanguageProvider.Instance.Languages.SelectMany(l => l.LanguageInformation.SpecialModulesAliases != null ? l.LanguageInformation.SpecialModulesAliases : new Dictionary()); @@ -3052,77 +3017,42 @@ namespace CodeCompletion return nameInUses; } - private void add_unit_ref_for_import(ident_list importedModuleName, statement importStatement, as_statement_list asStatementsList, string curr_path, - SymScope cur_scope, Hashtable ns_cache, bool allow_import_types, - using_namespace_list unl, bool caseSensitiveSearch) + private void CompileImportedUnit(string importedName, statement importStatement, as_statement_list asStatementsList, string curr_path, + SymScope cur_scope, using_namespace_list unl, bool caseSensitiveSearch) { try { - string str = ""; - for (int i = 0; i < importedModuleName.idents.Count; i++) + // на случай имен модулей, отличающихся от имен файла EVA + string realName = GetRealNameForModule(importedName); + + string pcu_unit_name = FindPCUFileName(realName, curr_path, caseSensitiveSearch); + string unit_name = CodeCompletionNameHelper.FindSourceFileName(realName, out _, caseSensitiveSearch, curr_path); + + if (unit_name != null) { - str += importedModuleName.idents[i].name; - - string realName = str; - - if (importedModuleName.idents.Count == 1) + DomConverter dc = (DomConverter)CodeCompletionController.comp_modules[unit_name] + ?? new CodeCompletionController().CompileAllIfNeed(unit_name, true); + + if (dc.visitor != null) { - // на случай имен модулей, отличающихся от имен файла EVA - realName = GetRealNameForModule(str); + dc.visitor.entry_scope.InitAssemblies(); + AddImportedNamesToCurScope(importStatement, asStatementsList, cur_scope, importedName, dc.visitor.entry_scope); } - - NamespaceScope ns_scope = null; - if (i == 0) - { - string pcu_unit_name = FindPCUFileName(realName, curr_path, caseSensitiveSearch); - string unit_name = CodeCompletionNameHelper.FindSourceFileName(realName, out _, caseSensitiveSearch, curr_path); - - if (unit_name != null) - { - DomConverter dc = CodeCompletionController.comp_modules[unit_name] as DomConverter; - if (dc == null) - { - dc = new CodeCompletionController().CompileAllIfNeed(unit_name, true); - } - if (dc.visitor != null) - { - dc.visitor.entry_scope.InitAssemblies(); - AddImportedNamesToCurScope(importStatement, asStatementsList, cur_scope, str, dc.visitor.entry_scope); - } - } - else - { - unit_name = pcu_unit_name; - if (unit_name != null) - { - IntellisensePCUReader pcu_rdr = new IntellisensePCUReader(); - SymScope ss = pcu_rdr.GetUnit(unit_name); - UnitDocCache.Load(ss, unit_name); - AddImportedNamesToCurScope(importStatement, asStatementsList, cur_scope, str, ss); - } - else - { - if (CodeCompletion.CodeCompletionController.pabcNamespaces.ContainsKey(str.ToLower())) - { - InterfaceUnitScope un_scope = CodeCompletion.CodeCompletionController.pabcNamespaces[str.ToLower()]; - AddImportedNamesToCurScope(importStatement, asStatementsList, cur_scope, str, un_scope); - } - else if (PascalABCCompiler.NetHelper.NetHelper.IsNetNamespace(str)) - { - ns_scope = new NamespaceScope(str); - ns_cache[str] = str; - AddImportedNamesToCurScope(importStatement, asStatementsList, cur_scope, str, ns_scope, importedModuleName.idents.Count > 1); - } - } - } - } - if (i == importedModuleName.idents.Count - 1 && i > 0) - AddImportedNamesToCurScope(importStatement, asStatementsList, cur_scope, str, ns_scope, false); - - if (i < importedModuleName.idents.Count - 1) - str += "."; } - unl.AddElement(new using_namespace(str)); + else + { + unit_name = pcu_unit_name; + + if (unit_name != null) + { + IntellisensePCUReader pcu_rdr = new IntellisensePCUReader(); + SymScope ss = pcu_rdr.GetUnit(unit_name); + UnitDocCache.Load(ss, unit_name); + AddImportedNamesToCurScope(importStatement, asStatementsList, cur_scope, importedName, ss); + } + } + + unl.AddElement(new using_namespace(importedName)); } catch (Exception e) { @@ -3132,7 +3062,7 @@ namespace CodeCompletion } } - private static void AddImportedNamesToCurScope(statement importStatement, as_statement_list asStatementsList, SymScope currentScope, string importedModuleName, SymScope importedModuleScope, bool notFinalNamespaceName = false) + private static void AddImportedNamesToCurScope(statement importStatement, as_statement_list asStatementsList, SymScope currentScope, string importedModuleName, SymScope importedModuleScope) { int fictiveUnitIndex = currentScope.used_units.FindIndex(unit => unit.Name == importedModuleName); @@ -3153,7 +3083,7 @@ namespace CodeCompletion importedModuleScope.si.name = importedModuleName; importedModuleScope.si.addit_name = aliasName; } - else if (importStatement is from_import_statement fromImport && !notFinalNamespaceName) + else if (importStatement is from_import_statement fromImport) { if (fromImport.is_star) { @@ -3193,7 +3123,13 @@ namespace CodeCompletion List namespaces = new List(); PascalABCCompiler.NetHelper.NetHelper.init_namespaces(_as); AssemblyDocCache.Load(_as, path); - namespaces.AddRange(PascalABCCompiler.NetHelper.NetHelper.GetNamespaces(_as)); + + currentUnitLanguage = Languages.Facade.LanguageProvider.Instance.SelectLanguageByName(_program_module.Language); + + // Пока что добавили возможость грубо отключить добавление NET пространств имен по умолчанию здесь EVA + if (currentUnitLanguage.LanguageInformation.AddStandardNetNamespacesToUserScope) + namespaces.AddRange(PascalABCCompiler.NetHelper.NetHelper.GetNamespaces(_as)); + //List netScopes = new List(); //PascalABCCompiler.NetHelper.NetScope ns=new PascalABCCompiler.NetHelper.NetScope(unl,_as,tcst); InterfaceUnitScope unit_scope = null; @@ -3299,8 +3235,6 @@ namespace CodeCompletion } } - currentUnitLanguage = Languages.Facade.LanguageProvider.Instance.SelectLanguageByName(_program_module.Language); - if (currentUnitLanguage.ApplySyntaxTreeConvertersForIntellisense) { foreach (ISyntaxTreeConverter converter in currentUnitLanguage.SyntaxTreeConverters) @@ -3317,13 +3251,12 @@ namespace CodeCompletion unit_scope.uses_source_range = get_location(_program_module.used_units); - //foreach (unit_or_namespace s in _program_module.used_units.units) + // компиляция зависимостей из секции uses for (int j = _program_module.used_units.units.Count - 1; j >= 0; j--) { unit_or_namespace s = _program_module.used_units.units[j]; - add_unit_ref(s, Path.GetDirectoryName(_program_module.file_name), - cur_scope, ns_cache, semantic_options.allow_import_types, - unl, currentUnitLanguage.CaseSensitive); + CompileUsedUnitOrNamespace(s, Path.GetDirectoryName(_program_module.file_name), + cur_scope, ns_cache, unl, currentUnitLanguage.CaseSensitive); } } @@ -3341,17 +3274,13 @@ namespace CodeCompletion AddStandardUnit(unitName, currentUnitLanguage.CaseSensitive, currentUnitLanguage.LanguageInformation.AddStandardUnitNamesToUserScope); } - // Пока что добавили возможость грубо отключить добавление NET пространств имен по умолчанию здесь EVA - if (currentUnitLanguage.LanguageInformation.AddStandardNetNamespacesToUserScope) + foreach (string s in namespaces) { - foreach (string s in namespaces) + if (!ns_cache.ContainsKey(s)) { - if (!ns_cache.ContainsKey(s)) - { - NamespaceScope ns_scope = new NamespaceScope(s); - cur_scope.AddName(s, ns_scope); - ns_cache[s] = s; - } + NamespaceScope ns_scope = new NamespaceScope(s); + cur_scope.AddName(s, ns_scope); + ns_cache[s] = s; } } @@ -3414,20 +3343,18 @@ namespace CodeCompletion { foreach (var unitNode in import.modules_names.as_statements.Select(st => st.real_name).Reverse()) { - add_unit_ref_for_import(new ident_list(unitNode), import, import.modules_names, + CompileImportedUnit(unitNode.name, import, import.modules_names, Path.GetDirectoryName(fileName), - cur_scope, ns_cache, semantic_options.allow_import_types, - unl, caseSensitiveSearch); + cur_scope, unl, caseSensitiveSearch); usedUnitNames.Add(unitNode.name); } } else if (importStatement is from_import_statement fromImport) { - add_unit_ref_for_import(new ident_list(fromImport.module_name), fromImport, fromImport.imported_names, + CompileImportedUnit(fromImport.module_name.name, fromImport, fromImport.imported_names, Path.GetDirectoryName(fileName), - cur_scope, ns_cache, semantic_options.allow_import_types, - unl, caseSensitiveSearch); + cur_scope, unl, caseSensitiveSearch); usedUnitNames.Add(fromImport.module_name.name); } @@ -5118,9 +5045,8 @@ namespace CodeCompletion for (int j = _implementation_node.uses_modules.units.Count - 1; j >= 0; j--) { unit_or_namespace s = _implementation_node.uses_modules.units[j]; - add_unit_ref(s, Path.GetDirectoryName(this.cur_unit_file_name), - cur_scope, ns_cache, semantic_options.allow_import_types, - unl, currentLanguage.CaseSensitive); + CompileUsedUnitOrNamespace(s, Path.GetDirectoryName(this.cur_unit_file_name), + cur_scope, ns_cache, unl, currentLanguage.CaseSensitive); } } impl_scope = cur_scope; diff --git a/CodeCompletion/SymTable.cs b/CodeCompletion/SymTable.cs index 0d179bfff..1fa96f8b6 100644 --- a/CodeCompletion/SymTable.cs +++ b/CodeCompletion/SymTable.cs @@ -5387,7 +5387,7 @@ namespace CodeCompletion // // } - public class NamespaceTypeScope : SymScope, INamespaceTypeScope + /*public class NamespaceTypeScope : SymScope, INamespaceTypeScope { private CompiledScope entry_type; @@ -5433,7 +5433,7 @@ namespace CodeCompletion { return entry_type.GetStaticNames(); } - } + }*/ public class NamespaceScope : SymScope, INamespaceScope { diff --git a/Compiler/Compiler.cs b/Compiler/Compiler.cs index e923babf5..50bb6a1cf 100644 --- a/Compiler/Compiler.cs +++ b/Compiler/Compiler.cs @@ -448,13 +448,13 @@ namespace PascalABCCompiler } //для поиска pcu в третью очередь исп. путь к pas файлу - public Hashtable StandardDirectories; + public Dictionary StandardDirectories; private void SetDirectories() { SystemDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName); - StandardDirectories = new Hashtable(StringComparer.InvariantCultureIgnoreCase) + StandardDirectories = new Dictionary(StringComparer.InvariantCultureIgnoreCase) { { "%PABCSYSTEM%", SystemDirectory } }; diff --git a/CompilerTools/Tools.cs b/CompilerTools/Tools.cs index 95e59d934..516cd2108 100644 --- a/CompilerTools/Tools.cs +++ b/CompilerTools/Tools.cs @@ -20,11 +20,11 @@ namespace PascalABCCompiler sc.begin_position.line_num, sc.begin_position.column_num, sc.end_position.line_num, sc.end_position.column_num); } - public static string ReplaceAllKeys(string str, Hashtable hashtable) + public static string ReplaceAllKeys(string str, Dictionary hashtable) { foreach (string key in hashtable.Keys) if (hashtable[key] != null) - str = str.Replace(key, hashtable[key].ToString()); + str = str.Replace(key, hashtable[key]); return str; } diff --git a/NETGenerator/CodeGenerator.cs b/NETGenerator/CodeGenerator.cs index a183b5175..2832af894 100644 --- a/NETGenerator/CodeGenerator.cs +++ b/NETGenerator/CodeGenerator.cs @@ -7,8 +7,7 @@ * ***************************************************************************/ -using System; -using System.Collections; +using System.Collections.Generic; using PascalABCCompiler.NetHelper; namespace PascalABCCompiler.CodeGenerators @@ -23,7 +22,7 @@ namespace PascalABCCompiler.CodeGenerators private NETGenerator.ILConverter il_converter;//=new NETGenerator.ILConverter(); public void GenerateILCodeAndSaveAssembly(SemanticTree.IProgramNode ProgramTree,string TargetFileName,string SourceFileName , - NETGenerator.CompilerOptions options, Hashtable StandartDirectories, string[] ResourceFiles) + NETGenerator.CompilerOptions options, Dictionary StandartDirectories, string[] ResourceFiles) { il_converter = new NETGenerator.ILConverter(StandartDirectories); il_converter.ConvertFromTree(ProgramTree, TargetFileName, SourceFileName, options, ResourceFiles); diff --git a/NETGenerator/NETGenerator.cs b/NETGenerator/NETGenerator.cs index c15d8758d..cd7e0afb5 100644 --- a/NETGenerator/NETGenerator.cs +++ b/NETGenerator/NETGenerator.cs @@ -271,9 +271,9 @@ namespace PascalABCCompiler.NETGenerator make_next_spoint = true; } - private Hashtable StandartDirectories; + private Dictionary StandartDirectories; - public ILConverter(Hashtable StandartDirectories) + public ILConverter(Dictionary StandartDirectories) { this.StandartDirectories = StandartDirectories; } diff --git a/VisualPascalABCNET/DS/VisualEnvironmentCompiler.cs b/VisualPascalABCNET/DS/VisualEnvironmentCompiler.cs index 0405df955..72c844a7d 100644 --- a/VisualPascalABCNET/DS/VisualEnvironmentCompiler.cs +++ b/VisualPascalABCNET/DS/VisualEnvironmentCompiler.cs @@ -62,7 +62,7 @@ namespace VisualPascalABC private DebugHelper DebugHelper; private CodeCompletionParserController CodeCompletionParserController; public UserOptions UserOptions; - private System.Collections.Hashtable StandartDirectories; + private Dictionary StandartDirectories; Dictionary OpenDocuments; public VisualEnvironmentCompiler(InvokeDegegate beginInvoke, @@ -70,7 +70,7 @@ namespace VisualPascalABC SetTextDelegate addTextToCompilerMessages, ToolStripMenuItem pluginsMenuItem, ToolStrip pluginsToolStrip, ExecuteSourceLocationActionDelegate ExecuteSLAction, ExecuteVisualEnvironmentCompilerActionDelegate ExecuteVECAction, - PascalABCCompiler.Errors.ErrorsStrategyManager ErrorsManager, RunManager RunnerManager, DebugHelper DebugHelper,UserOptions UserOptions,System.Collections.Hashtable StandartDirectories, + PascalABCCompiler.Errors.ErrorsStrategyManager ErrorsManager, RunManager RunnerManager, DebugHelper DebugHelper,UserOptions UserOptions, Dictionary StandartDirectories, Dictionary OpenDocuments, IWorkbench workbench) { this.StandartDirectories = StandartDirectories; diff --git a/VisualPascalABCNET/DockContent/CodeFileDocumentTextEditorControl.cs b/VisualPascalABCNET/DockContent/CodeFileDocumentTextEditorControl.cs index 50fe70eee..982d6660c 100644 --- a/VisualPascalABCNET/DockContent/CodeFileDocumentTextEditorControl.cs +++ b/VisualPascalABCNET/DockContent/CodeFileDocumentTextEditorControl.cs @@ -117,7 +117,8 @@ namespace VisualPascalABC public void UpdateFolding() { - CodeCompletionParserController.open_files[this.FileName] = true; + if (Languages.Facade.LanguageProvider.Instance.HasLanguageForExtension(FileName)) + CodeCompletionParserController.filesToParse[FileName] = true; } public void CollapseRegions() diff --git a/VisualPascalABCNET/Form1.cs b/VisualPascalABCNET/Form1.cs index 95ed6db7b..19680e186 100644 --- a/VisualPascalABCNET/Form1.cs +++ b/VisualPascalABCNET/Form1.cs @@ -297,7 +297,7 @@ namespace VisualPascalABC PlayPauseButtonsVisibleInPanel = false; - WorkbenchStorage.StandartDirectories = new Hashtable(StringComparer.InvariantCultureIgnoreCase); + WorkbenchStorage.StandartDirectories = new Dictionary(StringComparer.InvariantCultureIgnoreCase); WorkbenchStorage.StandartDirectories.Add(Constants.SystemDirectoryIdent, System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName)); RestoreDesktop(); @@ -614,10 +614,11 @@ namespace VisualPascalABC case VisualEnvironmentCompilerAction.OpenFile: return WorkbenchServiceFactory.FileService.OpenFile((string)obj, null); case VisualEnvironmentCompilerAction.GetDirectory: - string s=VisualEnvironmentCompiler.Compiler.CompilerOptions.StandardDirectories[(string)obj] as string; - if (s != null) + VisualEnvironmentCompiler.Compiler.CompilerOptions.StandardDirectories.TryGetValue((string)obj, out var s); + if (s != null) return s; - return WorkbenchStorage.StandartDirectories[(string)obj] as string; + WorkbenchStorage.StandartDirectories.TryGetValue((string)obj, out s); + return s; case VisualEnvironmentCompilerAction.PT4PositionCursorAfterTask: // SSM 09.11.19 { var ta = CurrentCodeFileDocument.TextEditor.ActiveTextAreaControl.TextArea; diff --git a/VisualPascalABCNET/IB/CodeCompletion/CodeCompletionParserController.cs b/VisualPascalABCNET/IB/CodeCompletion/CodeCompletionParserController.cs index 61b5b8819..0f9170d72 100644 --- a/VisualPascalABCNET/IB/CodeCompletion/CodeCompletionParserController.cs +++ b/VisualPascalABCNET/IB/CodeCompletion/CodeCompletionParserController.cs @@ -10,7 +10,7 @@ namespace VisualPascalABC public class CodeCompletionParserController : VisualPascalABCPlugins.ICodeCompletionService { - public static Dictionary open_files = new Dictionary(StringComparer.OrdinalIgnoreCase); + public static Dictionary filesToParse = new Dictionary(StringComparer.OrdinalIgnoreCase); public VisualEnvironmentCompiler visualEnvironmentCompiler; private System.Threading.Thread th = null; private CodeCompletionProvider ccp; @@ -67,40 +67,42 @@ namespace VisualPascalABC CodeCompletion.CodeCompletionController.comp_modules[NewFileName] = CodeCompletion.CodeCompletionController.comp_modules[OldFileName]; if (CodeCompletion.CodeCompletionController.comp_modules.ContainsKey(OldFileName)) CodeCompletion.CodeCompletionController.comp_modules.Remove(OldFileName); - open_files[NewFileName] = open_files[OldFileName]; - if (open_files.ContainsKey(OldFileName)) - open_files.Remove(OldFileName); + filesToParse[NewFileName] = filesToParse[OldFileName]; + if (filesToParse.ContainsKey(OldFileName)) + filesToParse.Remove(OldFileName); } } public void RegisterFileForParsing(string FileName) { - open_files[FileName] = true; - CodeCompletion.CodeCompletionController.SetLanguage(FileName); - //ParseAllFiles(); + if (Languages.Facade.LanguageProvider.Instance.HasLanguageForExtension(FileName)) + { + filesToParse[FileName] = true; + CodeCompletion.CodeCompletionController.SetLanguage(FileName); + } } public void CloseFile(string FileName) { if (CodeCompletion.CodeCompletionController.comp_modules[FileName] != null) CodeCompletion.CodeCompletionController.comp_modules.Remove(FileName); - open_files.Remove(FileName); + filesToParse.Remove(FileName); } public void SetAsChanged(string FileName) { - if (FileName != null) - open_files[FileName] = true; + if (FileName != null && filesToParse.ContainsKey(FileName)) + filesToParse[FileName] = true; } public void SetAllInProjectChanged() { try { - foreach (string s in open_files.Keys.ToArray()) + foreach (string s in filesToParse.Keys.ToArray()) { if (ProjectFactory.Instance.CurrentProject.ContainsSourceFile(s)) - open_files[s] = true; + filesToParse[s] = true; } } catch (Exception) { } @@ -146,10 +148,10 @@ namespace VisualPascalABC { Dictionary recomp_files = new Dictionary(StringComparer.OrdinalIgnoreCase); bool is_comp = false; - foreach (string FileName in open_files.Keys.ToArray()) // копирование ключей обязательно, иначе будет InvalidOperationException EVA + foreach (string FileName in filesToParse.Keys.ToArray()) // копирование ключей обязательно, иначе будет InvalidOperationException EVA { - if (open_files[FileName]) + if (filesToParse[FileName]) { is_comp = true; CodeCompletion.CodeCompletionController controller = new CodeCompletion.CodeCompletionController(); @@ -160,7 +162,7 @@ namespace VisualPascalABC long cur_mem = Environment.WorkingSet; CodeCompletion.DomConverter dc = controller.Compile(FileName, text); mem_delta += Environment.WorkingSet - cur_mem; - open_files[FileName] = false; + filesToParse[FileName] = false; if (dc.is_compiled) { //CodeCompletion.CodeCompletionController.comp_modules.Remove(file_name); @@ -172,7 +174,7 @@ namespace VisualPascalABC } CodeCompletion.CodeCompletionController.comp_modules[FileName] = dc; recomp_files[FileName] = FileName; - open_files[FileName] = false; + filesToParse[FileName] = false; if (ParseInformationUpdated != null) ParseInformationUpdated(dc.visitor.entry_scope, FileName); } @@ -180,7 +182,7 @@ namespace VisualPascalABC CodeCompletion.CodeCompletionController.comp_modules[FileName] = dc; } } - foreach (string FileName in open_files.Keys.ToArray()) // копирование ключей обязательно, иначе будет InvalidOperationException EVA + foreach (string FileName in filesToParse.Keys.ToArray()) // копирование ключей обязательно, иначе будет InvalidOperationException EVA { CodeCompletion.DomConverter dc = CodeCompletion.CodeCompletionController.comp_modules[FileName] as CodeCompletion.DomConverter; CodeCompletion.SymScope ss = null; @@ -206,7 +208,7 @@ namespace VisualPascalABC for (int i = 0; i < ss.used_units.Count; i++) { string s = ss.used_units[i].file_name; - if (s != null && open_files.ContainsKey(s) && recomp_files.ContainsKey(s)) + if (s != null && filesToParse.ContainsKey(s) && recomp_files.ContainsKey(s)) { is_comp = true; CodeCompletion.CodeCompletionController controller = new CodeCompletion.CodeCompletionController(); @@ -215,7 +217,7 @@ namespace VisualPascalABC long cur_mem = Environment.WorkingSet; dc = controller.Compile(FileName, text); mem_delta += Environment.WorkingSet - cur_mem; - open_files[FileName] = false; + filesToParse[FileName] = false; CodeCompletion.CodeCompletionController.comp_modules[FileName] = dc; if (dc.is_compiled) { diff --git a/VisualPascalABCNET/IB/CodeCompletion/CodeCompletionProvider.cs b/VisualPascalABCNET/IB/CodeCompletion/CodeCompletionProvider.cs index 00828c767..065d3c3f9 100644 --- a/VisualPascalABCNET/IB/CodeCompletion/CodeCompletionProvider.cs +++ b/VisualPascalABCNET/IB/CodeCompletion/CodeCompletionProvider.cs @@ -257,7 +257,7 @@ namespace VisualPascalABC } if (fnd_scope != null) { - foreach (string FileName in CodeCompletionParserController.open_files.Keys) + foreach (string FileName in CodeCompletionParserController.filesToParse.Keys) { CodeCompletion.CodeCompletionController controller = new CodeCompletion.CodeCompletionController(); string text = VisualPABCSingleton.MainForm.VisualEnvironmentCompiler.SourceFilesProvider(FileName, PascalABCCompiler.SourceFileOperation.GetText) as string; diff --git a/VisualPascalABCNET/Workbench/BuildService.cs b/VisualPascalABCNET/Workbench/BuildService.cs index 26d99b179..0328ae04a 100644 --- a/VisualPascalABCNET/Workbench/BuildService.cs +++ b/VisualPascalABCNET/Workbench/BuildService.cs @@ -68,7 +68,7 @@ namespace VisualPascalABC CompilerOptions1.UseDllForSystemUnits = false; CompilerOptions1.RunWithEnvironment = RunWithEnvironment; bool savePCU = Workbench.VisualEnvironmentCompiler.Compiler.InternalDebug.PCUGenerate; - if (Path.GetDirectoryName(CompilerOptions1.SourceFileName).ToLower() == ((string)WorkbenchStorage.StandartDirectories[Constants.LibSourceDirectoryIdent]).ToLower()) + if (Path.GetDirectoryName(CompilerOptions1.SourceFileName).ToLower() == WorkbenchStorage.StandartDirectories[Constants.LibSourceDirectoryIdent].ToLower()) Workbench.VisualEnvironmentCompiler.Compiler.InternalDebug.PCUGenerate = false; if (RuntimeServicesModule != null) @@ -128,7 +128,7 @@ namespace VisualPascalABC //CompilerOptions1.SavePCUInThreadPull = true; bool savePCU = Workbench.VisualEnvironmentCompiler.Compiler.InternalDebug.PCUGenerate; - if (Path.GetDirectoryName(FileName).ToLower() == ((string)WorkbenchStorage.StandartDirectories[Constants.LibSourceDirectoryIdent]).ToLower()) + if (Path.GetDirectoryName(FileName).ToLower() == WorkbenchStorage.StandartDirectories[Constants.LibSourceDirectoryIdent].ToLower()) Workbench.VisualEnvironmentCompiler.Compiler.InternalDebug.PCUGenerate = false; string ofn = Workbench.VisualEnvironmentCompiler.Compile(CompilerOptions1); @@ -220,7 +220,7 @@ namespace VisualPascalABC //CompilerOptions1.SavePCUInThreadPull = true; __savePCU = Workbench.VisualEnvironmentCompiler.Compiler.InternalDebug.PCUGenerate; - if (Path.GetDirectoryName(FileName).ToLower() == ((string)WorkbenchStorage.StandartDirectories[Constants.LibSourceDirectoryIdent]).ToLower()) + if (Path.GetDirectoryName(FileName).ToLower() == WorkbenchStorage.StandartDirectories[Constants.LibSourceDirectoryIdent].ToLower()) Workbench.VisualEnvironmentCompiler.Compiler.InternalDebug.PCUGenerate = false; Workbench.VisualEnvironmentCompiler.Compiler.OnChangeCompilerState += CompilationOnChangeCompilerState; diff --git a/VisualPascalABCNET/Workbench/WorkbenchServiceFactory.cs b/VisualPascalABCNET/Workbench/WorkbenchServiceFactory.cs index 969f89276..096329748 100644 --- a/VisualPascalABCNET/Workbench/WorkbenchServiceFactory.cs +++ b/VisualPascalABCNET/Workbench/WorkbenchServiceFactory.cs @@ -231,7 +231,7 @@ namespace VisualPascalABC internal static string WorkingDirectory = null; internal static string WorkingDirectoryInOptionsFile = null; internal static string LibSourceDirectory = null; - internal static Hashtable StandartDirectories; + internal static Dictionary StandartDirectories; internal static System.Threading.Thread MainProgramThread; internal static bool SetCurrentTabPageIfWriteToOutputWindow = false; internal static bool WorkingDirectoryExsist diff --git a/VisualPascalABCNETLinux/DS/VisualEnvironmentCompiler.cs b/VisualPascalABCNETLinux/DS/VisualEnvironmentCompiler.cs index ef425d46a..4ea70da68 100644 --- a/VisualPascalABCNETLinux/DS/VisualEnvironmentCompiler.cs +++ b/VisualPascalABCNETLinux/DS/VisualEnvironmentCompiler.cs @@ -60,7 +60,7 @@ namespace VisualPascalABC private DebugHelper DebugHelper; private CodeCompletionParserController CodeCompletionParserController; public UserOptions UserOptions; - private System.Collections.Hashtable StandartDirectories; + private Dictionary StandartDirectories; Dictionary OpenDocuments; public VisualEnvironmentCompiler(InvokeDegegate beginInvoke, @@ -68,7 +68,7 @@ namespace VisualPascalABC SetTextDelegate addTextToCompilerMessages, ToolStripMenuItem pluginsMenuItem, ToolStrip pluginsToolStrip, ExecuteSourceLocationActionDelegate ExecuteSLAction, ExecuteVisualEnvironmentCompilerActionDelegate ExecuteVECAction, - PascalABCCompiler.Errors.ErrorsStrategyManager ErrorsManager, RunManager RunnerManager, DebugHelper DebugHelper,UserOptions UserOptions,System.Collections.Hashtable StandartDirectories, + PascalABCCompiler.Errors.ErrorsStrategyManager ErrorsManager, RunManager RunnerManager, DebugHelper DebugHelper,UserOptions UserOptions, Dictionary StandartDirectories, Dictionary OpenDocuments, IWorkbench workbench) { this.StandartDirectories = StandartDirectories; diff --git a/VisualPascalABCNETLinux/DockContent/CodeFileDocumentTextEditorControl.cs b/VisualPascalABCNETLinux/DockContent/CodeFileDocumentTextEditorControl.cs index bb1601c41..5912fe19f 100644 --- a/VisualPascalABCNETLinux/DockContent/CodeFileDocumentTextEditorControl.cs +++ b/VisualPascalABCNETLinux/DockContent/CodeFileDocumentTextEditorControl.cs @@ -114,12 +114,13 @@ namespace VisualPascalABC { ActiveTextAreaControl.TextArea.Refresh(ActiveTextAreaControl.TextArea.FoldMargin); } - - public void UpdateFolding() - { - CodeCompletionParserController.open_files[this.FileName] = true; - } - + + public void UpdateFolding() + { + if (Languages.Facade.LanguageProvider.Instance.HasLanguageForExtension(FileName)) + CodeCompletionParserController.filesToParse[FileName] = true; + } + public void CollapseRegions() { foreach (FoldMarker marker in Document.FoldingManager.FoldMarker) diff --git a/VisualPascalABCNETLinux/Form1.cs b/VisualPascalABCNETLinux/Form1.cs index c96601f7d..685a9e79c 100644 --- a/VisualPascalABCNETLinux/Form1.cs +++ b/VisualPascalABCNETLinux/Form1.cs @@ -357,7 +357,7 @@ namespace VisualPascalABC PlayPauseButtonsVisibleInPanel = false; - WorkbenchStorage.StandartDirectories = new Hashtable(StringComparer.InvariantCultureIgnoreCase); + WorkbenchStorage.StandartDirectories = new Dictionary(StringComparer.InvariantCultureIgnoreCase); WorkbenchStorage.StandartDirectories.Add(Constants.SystemDirectoryIdent, System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName)); //--------------------------------------------- @@ -707,10 +707,11 @@ namespace VisualPascalABC case VisualEnvironmentCompilerAction.OpenFile: return WorkbenchServiceFactory.FileService.OpenFile((string)obj, null); case VisualEnvironmentCompilerAction.GetDirectory: - string s=VisualEnvironmentCompiler.Compiler.CompilerOptions.StandardDirectories[(string)obj] as string; - if (s != null) + VisualEnvironmentCompiler.Compiler.CompilerOptions.StandardDirectories.TryGetValue((string)obj, out var s); + if (s != null) return s; - return WorkbenchStorage.StandartDirectories[(string)obj] as string; + WorkbenchStorage.StandartDirectories.TryGetValue((string)obj, out s); + return s; case VisualEnvironmentCompilerAction.PT4PositionCursorAfterTask: // SSM 09.11.19 { var ta = CurrentCodeFileDocument.TextEditor.ActiveTextAreaControl.TextArea; diff --git a/VisualPascalABCNETLinux/IB/CodeCompletion/CodeCompletionParserController.cs b/VisualPascalABCNETLinux/IB/CodeCompletion/CodeCompletionParserController.cs index 8543d1fe0..adf43c72f 100644 --- a/VisualPascalABCNETLinux/IB/CodeCompletion/CodeCompletionParserController.cs +++ b/VisualPascalABCNETLinux/IB/CodeCompletion/CodeCompletionParserController.cs @@ -10,7 +10,7 @@ namespace VisualPascalABC public class CodeCompletionParserController : VisualPascalABCPlugins.ICodeCompletionService { - public static Dictionary open_files = new Dictionary(StringComparer.OrdinalIgnoreCase); + public static Dictionary filesToParse = new Dictionary(StringComparer.OrdinalIgnoreCase); public VisualEnvironmentCompiler visualEnvironmentCompiler; private System.Threading.Thread th = null; private CodeCompletionProvider ccp; @@ -68,40 +68,42 @@ namespace VisualPascalABC CodeCompletion.CodeCompletionController.comp_modules[NewFileName] = CodeCompletion.CodeCompletionController.comp_modules[OldFileName]; if (CodeCompletion.CodeCompletionController.comp_modules.ContainsKey(OldFileName)) CodeCompletion.CodeCompletionController.comp_modules.Remove(OldFileName); - open_files[NewFileName] = open_files[OldFileName]; - if (open_files.ContainsKey(OldFileName)) - open_files.Remove(OldFileName); + filesToParse[NewFileName] = filesToParse[OldFileName]; + if (filesToParse.ContainsKey(OldFileName)) + filesToParse.Remove(OldFileName); } } public void RegisterFileForParsing(string FileName) { - open_files[FileName] = true; - CodeCompletion.CodeCompletionController.SetLanguage(FileName); - //ParseAllFiles(); + if (Languages.Facade.LanguageProvider.Instance.HasLanguageForExtension(FileName)) + { + filesToParse[FileName] = true; + CodeCompletion.CodeCompletionController.SetLanguage(FileName); + } } public void CloseFile(string FileName) { if (CodeCompletion.CodeCompletionController.comp_modules[FileName] != null) CodeCompletion.CodeCompletionController.comp_modules.Remove(FileName); - open_files.Remove(FileName); + filesToParse.Remove(FileName); } public void SetAsChanged(string FileName) { - if (FileName != null) - open_files[FileName] = true; + if (FileName != null && filesToParse.ContainsKey(FileName)) + filesToParse[FileName] = true; } public void SetAllInProjectChanged() { try { - foreach (string s in open_files.Keys.ToArray()) + foreach (string s in filesToParse.Keys.ToArray()) { if (ProjectFactory.Instance.CurrentProject.ContainsSourceFile(s)) - open_files[s] = true; + filesToParse[s] = true; } } catch (Exception e) @@ -151,10 +153,10 @@ namespace VisualPascalABC { Dictionary recomp_files = new Dictionary(StringComparer.OrdinalIgnoreCase); bool is_comp = false; - foreach (string FileName in open_files.Keys.ToArray()) // копирование ключей обязательно, иначе будет InvalidOperationException EVA + foreach (string FileName in filesToParse.Keys.ToArray()) // копирование ключей обязательно, иначе будет InvalidOperationException EVA { - if (open_files[FileName]) + if (filesToParse[FileName]) { is_comp = true; CodeCompletion.CodeCompletionController controller = new CodeCompletion.CodeCompletionController(); @@ -165,7 +167,7 @@ namespace VisualPascalABC long cur_mem = Environment.WorkingSet; CodeCompletion.DomConverter dc = controller.Compile(FileName, text); mem_delta += Environment.WorkingSet - cur_mem; - open_files[FileName] = false; + filesToParse[FileName] = false; if (dc.is_compiled) { //CodeCompletion.CodeCompletionController.comp_modules.Remove(file_name); @@ -177,7 +179,7 @@ namespace VisualPascalABC } CodeCompletion.CodeCompletionController.comp_modules[FileName] = dc; recomp_files[FileName] = FileName; - open_files[FileName] = false; + filesToParse[FileName] = false; if (ParseInformationUpdated != null) ParseInformationUpdated(dc.visitor.entry_scope, FileName); } @@ -185,7 +187,7 @@ namespace VisualPascalABC CodeCompletion.CodeCompletionController.comp_modules[FileName] = dc; } } - foreach (string FileName in open_files.Keys.ToArray()) // копирование ключей обязательно, иначе будет InvalidOperationException EVA + foreach (string FileName in filesToParse.Keys.ToArray()) // копирование ключей обязательно, иначе будет InvalidOperationException EVA { CodeCompletion.DomConverter dc = CodeCompletion.CodeCompletionController.comp_modules[FileName] as CodeCompletion.DomConverter; CodeCompletion.SymScope ss = null; @@ -211,7 +213,7 @@ namespace VisualPascalABC for (int i = 0; i < ss.used_units.Count; i++) { string s = ss.used_units[i].file_name; - if (s != null && open_files.ContainsKey(s) && recomp_files.ContainsKey(s)) + if (s != null && filesToParse.ContainsKey(s) && recomp_files.ContainsKey(s)) { is_comp = true; CodeCompletion.CodeCompletionController controller = new CodeCompletion.CodeCompletionController(); @@ -220,7 +222,7 @@ namespace VisualPascalABC long cur_mem = Environment.WorkingSet; dc = controller.Compile(FileName, text); mem_delta += Environment.WorkingSet - cur_mem; - open_files[FileName] = false; + filesToParse[FileName] = false; CodeCompletion.CodeCompletionController.comp_modules[FileName] = dc; if (dc.is_compiled) { diff --git a/VisualPascalABCNETLinux/IB/CodeCompletion/CodeCompletionProvider.cs b/VisualPascalABCNETLinux/IB/CodeCompletion/CodeCompletionProvider.cs index 962661070..cf5dbbe26 100644 --- a/VisualPascalABCNETLinux/IB/CodeCompletion/CodeCompletionProvider.cs +++ b/VisualPascalABCNETLinux/IB/CodeCompletion/CodeCompletionProvider.cs @@ -257,7 +257,7 @@ namespace VisualPascalABC } if (fnd_scope != null) { - foreach (string FileName in CodeCompletionParserController.open_files.Keys) + foreach (string FileName in CodeCompletionParserController.filesToParse.Keys) { CodeCompletion.CodeCompletionController controller = new CodeCompletion.CodeCompletionController(); string text = VisualPABCSingleton.MainForm.VisualEnvironmentCompiler.SourceFilesProvider(FileName, PascalABCCompiler.SourceFileOperation.GetText) as string; diff --git a/VisualPascalABCNETLinux/Workbench/BuildService.cs b/VisualPascalABCNETLinux/Workbench/BuildService.cs index f1d09c553..3bb72c13d 100644 --- a/VisualPascalABCNETLinux/Workbench/BuildService.cs +++ b/VisualPascalABCNETLinux/Workbench/BuildService.cs @@ -66,7 +66,7 @@ namespace VisualPascalABC CompilerOptions1.UseDllForSystemUnits = false; CompilerOptions1.RunWithEnvironment = RunWithEnvironment; bool savePCU = Workbench.VisualEnvironmentCompiler.Compiler.InternalDebug.PCUGenerate; - if (Path.GetDirectoryName(CompilerOptions1.SourceFileName).ToLower() == ((string)WorkbenchStorage.StandartDirectories[Constants.LibSourceDirectoryIdent]).ToLower()) + if (Path.GetDirectoryName(CompilerOptions1.SourceFileName).ToLower() == WorkbenchStorage.StandartDirectories[Constants.LibSourceDirectoryIdent].ToLower()) Workbench.VisualEnvironmentCompiler.Compiler.InternalDebug.PCUGenerate = false; if (RuntimeServicesModule != null) @@ -127,7 +127,7 @@ namespace VisualPascalABC //CompilerOptions1.SavePCUInThreadPull = true; bool savePCU = Workbench.VisualEnvironmentCompiler.Compiler.InternalDebug.PCUGenerate; - if (Path.GetDirectoryName(FileName).ToLower() == ((string)WorkbenchStorage.StandartDirectories[Constants.LibSourceDirectoryIdent]).ToLower()) + if (Path.GetDirectoryName(FileName).ToLower() == WorkbenchStorage.StandartDirectories[Constants.LibSourceDirectoryIdent].ToLower()) Workbench.VisualEnvironmentCompiler.Compiler.InternalDebug.PCUGenerate = false; //MessageBox.Show("111"); @@ -223,7 +223,7 @@ namespace VisualPascalABC //CompilerOptions1.SavePCUInThreadPull = true; __savePCU = Workbench.VisualEnvironmentCompiler.Compiler.InternalDebug.PCUGenerate; - if (Path.GetDirectoryName(FileName).ToLower() == ((string)WorkbenchStorage.StandartDirectories[Constants.LibSourceDirectoryIdent]).ToLower()) + if (Path.GetDirectoryName(FileName).ToLower() == WorkbenchStorage.StandartDirectories[Constants.LibSourceDirectoryIdent].ToLower()) Workbench.VisualEnvironmentCompiler.Compiler.InternalDebug.PCUGenerate = false; Workbench.VisualEnvironmentCompiler.Compiler.OnChangeCompilerState += CompilationOnChangeCompilerState; diff --git a/VisualPascalABCNETLinux/Workbench/WorkbenchServiceFactory.cs b/VisualPascalABCNETLinux/Workbench/WorkbenchServiceFactory.cs index 31e8ddd5e..0a0490612 100644 --- a/VisualPascalABCNETLinux/Workbench/WorkbenchServiceFactory.cs +++ b/VisualPascalABCNETLinux/Workbench/WorkbenchServiceFactory.cs @@ -231,7 +231,7 @@ namespace VisualPascalABC internal static string WorkingDirectory = null; internal static string WorkingDirectoryInOptionsFile = null; internal static string LibSourceDirectory = null; - internal static Hashtable StandartDirectories; + internal static Dictionary StandartDirectories; internal static System.Threading.Thread MainProgramThread; internal static bool SetCurrentTabPageIfWriteToOutputWindow = false; internal static bool WorkingDirectoryExsist diff --git a/bin/Lib/SPythonSystem.pas b/bin/Lib/SPythonSystem.pas index be81fa43a..c47ee1f55 100644 --- a/bin/Lib/SPythonSystem.pas +++ b/bin/Lib/SPythonSystem.pas @@ -1,10 +1,11 @@ {$HiddenIdents} unit SPythonSystem; -{$reference '%GAC%\System.dll'} -{$reference '%GAC%\mscorlib.dll'} -{$reference '%GAC%\System.Core.dll'} -{$reference '%GAC%\System.Numerics.dll'} +// В SPython данной версии нет возможности использовать пространства имен +// {$reference '%GAC%\System.dll'} +// {$reference '%GAC%\mscorlib.dll'} +// {$reference '%GAC%\System.Core.dll'} +// {$reference '%GAC%\System.Numerics.dll'} interface