/// <summary> /// Получить описание элемента при наведении мышью /// </summary> public string GetDescription(expression expr, string FileName, string expr_without_brackets, PascalABCCompiler.Parsers.Controller parser, int line, int col, PascalABCCompiler.Parsers.KeywordKind keyword, bool header) { if (stv.cur_scope == null) return null; SymScope ss = stv.FindScopeByLocation(line+1,col+1);//stv.cur_scope; if (ss == null) return null; if (!header && ss.IsInScope(ss.head_loc,line+1,col+1)) { List<PascalABCCompiler.Errors.Error> Errors = new List<PascalABCCompiler.Errors.Error>(); expr = parser.GetExpression("test"+Path.GetExtension(FileName), expr_without_brackets, Errors); if (expr == null || Errors.Count > 0) return null; } bool on_proc = false; SetCurrentUsedAssemblies(); if (keyword == PascalABCCompiler.Parsers.KeywordKind.Function || keyword == PascalABCCompiler.Parsers.KeywordKind.Constructor || keyword == PascalABCCompiler.Parsers.KeywordKind.Destructor) { if (ss is ProcRealization) { if (expr is ident) { if ((expr as ident).name == (ss as ProcRealization).def_proc.si.name) on_proc = true; } else on_proc = true; } else if (ss is ProcScope) { if (expr is ident) { if ((expr as ident).name == (ss as ProcScope).si.name) on_proc = true; } else on_proc = true; } } //if (!((keyword == KeywordKind.kw_proc || keyword == KeywordKind.kw_constr || keyword == KeywordKind.kw_destr) && ss is ProcScope)) if (!on_proc) { ExpressionVisitor ev = new ExpressionVisitor(expr, ss, stv); ev.mouse_hover = true; ss = ev.GetScopeOfExpression(); } if (ss != null && ss.si != null) { try { if (ss.si.has_doc != true) if (ss is CompiledScope) ss.AddDocumentation(AssemblyDocCache.GetDocumentation((ss as CompiledScope).ctn)); else if (ss is CompiledMethodScope) ss.AddDocumentation(AssemblyDocCache.GetDocumentation((ss as CompiledMethodScope).mi)); else if (ss is CompiledPropertyScope) ss.AddDocumentation(AssemblyDocCache.GetDocumentation((ss as CompiledPropertyScope).pi)); else if (ss is CompiledFieldScope) ss.AddDocumentation(AssemblyDocCache.GetDocumentation((ss as CompiledFieldScope).fi)); else if (ss is CompiledEventScope) ss.AddDocumentation(AssemblyDocCache.GetDocumentation((ss as CompiledEventScope).ei)); else if (ss is CompiledConstructorScope) ss.AddDocumentation(AssemblyDocCache.GetDocumentation((ss as CompiledConstructorScope).mi)); else if (ss is NamespaceScope) ss.AddDocumentation(AssemblyDocCache.GetDocumentationForNamespace((ss as NamespaceScope).name)); else if (ss is TypeScope) ss.AddDocumentation(UnitDocCache.GetDocumentation(ss as TypeScope)); else if (ss is ProcScope) ss.AddDocumentation(UnitDocCache.GetDocumentation(ss as ProcScope)); else if (ss is InterfaceUnitScope) ss.AddDocumentation(UnitDocCache.GetDocumentation(ss as InterfaceUnitScope)); else if (ss is ElementScope && string.IsNullOrEmpty(ss.si.description) && (ss as ElementScope).sc is TypeScope) ss.si.description = (ss as ElementScope).sc.Description; } catch (Exception e) { } RestoreCurrentUsedAssemblies(); string description = ss.si.description; if (description != null) description = description.Replace("!#",""); return description; } RestoreCurrentUsedAssemblies(); return null; }
/// <summary> /// Получить подсказку индекса /// </summary> public string[] GetIndex(expression expr, int line, int col) { if (stv.cur_scope == null) return null; SymScope si = stv.FindScopeByLocation(line+1,col+1);//stv.cur_scope; if (si == null) { si = stv.FindScopeByLocation(line,col+1); if (si == null) return null; } ExpressionVisitor ev = new ExpressionVisitor(expr, si, stv); si = ev.GetScopeOfExpression(false,true); return CodeCompletionController.CurrentParser.LanguageInformation.GetIndexerString(si); }
/// <summary> /// Получение имен после точки /// </summary> public SymInfo[] GetName(expression expr, string str, int line, int col, PascalABCCompiler.Parsers.KeywordKind keyword, ref SymScope root) { if (stv.cur_scope == null) return null; if (col + 1 > str.Length) col -= str.Length; SymScope si = stv.FindScopeByLocation(line + 1, col + 1);//stv.cur_scope; if (si == null) { si = stv.FindScopeByLocation(line, col + 1); if (si == null) return null; } SetCurrentUsedAssemblies(); ExpressionVisitor ev = new ExpressionVisitor(expr, si, stv); si = ev.GetScopeOfExpression(true, false); root = si; if (si is ElementScope) root = (si as ElementScope).sc; else if (si is ProcScope) root = (si as ProcScope).return_type; if (si != null) { if (!(si is TypeScope) && !(si is NamespaceScope)) { SymInfo[] syms = si.GetNamesAsInObject(ev); SymInfo[] ext_syms = null; if (si is ElementScope) ext_syms = stv.cur_scope.GetSymInfosForExtensionMethods((si as ElementScope).sc as TypeScope); List<SymInfo> lst = new List<SymInfo>(); lst.AddRange(syms); if (ext_syms != null) lst.AddRange(ext_syms); RestoreCurrentUsedAssemblies(); return lst.ToArray(); } else { if (si is TypeScope) { RestoreCurrentUsedAssemblies(); return (si as TypeScope).GetNames(ev, keyword, false); } else { if (ev.entry_scope.InUsesRange(line + 1, col + 1)) keyword = PascalABCCompiler.Parsers.KeywordKind.Uses; RestoreCurrentUsedAssemblies(); return (si as NamespaceScope).GetNames(ev, keyword); } } } RestoreCurrentUsedAssemblies(); return null; }
/// <summary> /// Получить реализацию expr /// </summary> public List<Position> GetRealization(expression expr, int line, int col, PascalABCCompiler.Parsers.KeywordKind keyword) { List<Position> poses = new List<Position>(); Position pos = new Position(); pos.line = -1; pos.column = -1; try { if (stv.cur_scope == null) return poses; SymScope ss = stv.FindScopeByLocation(line+1,col+1);//stv.cur_scope; if (ss == null) return poses; //if (!(expr is ident && string.Compare((expr as ident).name,ss.si.name) == 0)) bool on_proc = false; SetCurrentUsedAssemblies(); if (keyword == PascalABCCompiler.Parsers.KeywordKind.Function || keyword == PascalABCCompiler.Parsers.KeywordKind.Constructor || keyword == PascalABCCompiler.Parsers.KeywordKind.Destructor) { if (ss is ProcRealization) { if (expr is ident) { if ((expr as ident).name == (ss as ProcRealization).def_proc.si.name) on_proc = true; } else on_proc = true; } else if (ss is ProcScope) { if (expr is ident) { if ((expr as ident).name == (ss as ProcScope).si.name) on_proc = true; } else on_proc = true; } } //if (!((keyword == KeywordKind.kw_proc || keyword == KeywordKind.kw_constr || keyword == KeywordKind.kw_destr) && ss is ProcScope)) if (!on_proc) //if (keyword != KeywordKind.kw_proc && keyword != KeywordKind.kw_constr && keyword != KeywordKind.kw_destr) { ExpressionVisitor ev = new ExpressionVisitor(expr, ss, stv); ss = ev.GetScopeOfExpression(); } while (ss != null && ss is ProcScope && (ss as ProcScope).proc_realization != null && (ss as ProcScope).proc_realization.loc != null) { ProcRealization pr = (ss as ProcScope).proc_realization; pos.line = pr.loc.begin_line_num; pos.column = pr.loc.begin_column_num; pos.file_name = pr.loc.doc.file_name; poses.Add(pos); if (on_proc) break; //ss = (ss as ProcScope).nextProc; ss = null; } } catch (Exception e) { } RestoreCurrentUsedAssemblies(); return poses; }
/// <summary> /// Получить определение expr /// </summary> public List<Position> GetDefinition(expression expr, int line, int col, PascalABCCompiler.Parsers.KeywordKind keyword, bool only_check) { List<Position> poses = new List<Position>(); Position pos = new Position(); pos.line = -1; pos.column = -1; try { if (stv.cur_scope == null) return poses; SymScope ss = stv.FindScopeByLocation(line+1,col+1);//stv.cur_scope; if (ss == null) return poses; bool on_proc = false; SetCurrentUsedAssemblies(); if (keyword == PascalABCCompiler.Parsers.KeywordKind.Function || keyword == PascalABCCompiler.Parsers.KeywordKind.Constructor || keyword == PascalABCCompiler.Parsers.KeywordKind.Destructor) { if (ss is ProcRealization) { if (expr is ident) { if ((expr as ident).name == (ss as ProcRealization).def_proc.si.name) on_proc = true; } else on_proc = true; } else if (ss is ProcScope) { if (expr is ident) { if ((expr as ident).name == (ss as ProcScope).si.name) on_proc = true; } else on_proc = true; } } //if (!((keyword == KeywordKind.kw_proc || keyword == KeywordKind.kw_constr || keyword == KeywordKind.kw_destr) && ss is ProcScope)) if (!on_proc) //if (!((keyword == KeywordKind.kw_proc || keyword == KeywordKind.kw_constr || keyword == KeywordKind.kw_destr) && ss is ProcRealization)) { ExpressionVisitor ev = new ExpressionVisitor(expr, ss, stv); ss = ev.GetScopeOfExpression(); } else if (ss is ProcRealization) ss = (ss as ProcRealization).def_proc; if (ss != null) { if (ss.loc != null) { pos.line = ss.loc.begin_line_num; pos.column = ss.loc.begin_column_num; pos.file_name = ss.loc.doc.file_name; poses.Add(pos); } else if (ss is ProcScope && (ss as ProcScope).is_constructor) { ss = (ss as ProcScope).declaringType; if (ss.loc != null) { pos.line = ss.loc.begin_line_num; pos.column = ss.loc.begin_column_num; pos.file_name = ss.loc.doc.file_name; poses.Add(pos); } } else if (ss is CompiledScope) { pos.from_metadata = true; pos.line = 1; pos.column = 1; CompiledScope cs = ss as CompiledScope; pos.metadata_title = prepare_file_name(cs.CompiledType.Name); pos.full_metadata_title = cs.CompiledType.FullName; if (cs.CompiledType.IsInterface) pos.metadata_type = MetadataType.Interface; else if (cs.CompiledType.BaseType == typeof(Delegate) || cs.CompiledType.BaseType == typeof(MulticastDelegate)) pos.metadata_type = MetadataType.Delegate; else if (cs.CompiledType.IsEnum) pos.metadata_type = MetadataType.Enumeration; else if (cs.CompiledType.IsValueType) pos.metadata_type = MetadataType.Struct; else pos.metadata_type = MetadataType.Class; if (!only_check) { pos.metadata = CodeCompletionController.CurrentParser.LanguageInformation.GetCompiledTypeRepresentation(cs.CompiledType, cs.CompiledType, ref pos.line, ref pos.column); Type t = cs.CompiledType; int lines = 0; int ind = pos.metadata.IndexOf('\n'); pos.metadata = pos.metadata.Insert(ind + 1, get_references(t, out lines)); pos.line += lines; } poses.Add(pos); } else if (ss is CompiledFieldScope) { pos.from_metadata = true; pos.line = 1; pos.column = 1; CompiledFieldScope cfs = ss as CompiledFieldScope; if (cfs.CompiledField.DeclaringType.IsEnum) pos.metadata_type = MetadataType.EnumerationMember; else pos.metadata_type = MetadataType.Field; pos.metadata_title = prepare_file_name(cfs.CompiledField.DeclaringType.Name); if (!only_check) { pos.metadata = CodeCompletionController.CurrentParser.LanguageInformation.GetCompiledTypeRepresentation(cfs.CompiledField.DeclaringType, cfs.CompiledField, ref pos.line, ref pos.column); Type t = cfs.CompiledField.DeclaringType; int lines = 0; int ind = pos.metadata.IndexOf('\n'); pos.metadata = pos.metadata.Insert(ind + 1, get_references(t, out lines)); pos.line += lines; } pos.full_metadata_title = cfs.CompiledField.DeclaringType.FullName + "." + cfs.CompiledField.Name; poses.Add(pos); } else if (ss is CompiledMethodScope) { pos.from_metadata = true; pos.line = 1; pos.column = 1; CompiledMethodScope cms = ss as CompiledMethodScope; pos.metadata_title = prepare_file_name(cms.CompiledMethod.DeclaringType.Name); pos.metadata_type = MetadataType.Method; if (!only_check) { pos.metadata = CodeCompletionController.CurrentParser.LanguageInformation.GetCompiledTypeRepresentation(cms.CompiledMethod.DeclaringType, cms.CompiledMethod, ref pos.line, ref pos.column); Type t = cms.CompiledMethod.DeclaringType; int lines = 0; int ind = pos.metadata.IndexOf('\n'); pos.metadata = pos.metadata.Insert(ind + 1, get_references(t, out lines)); pos.line += lines; } pos.full_metadata_title = cms.CompiledMethod.DeclaringType.FullName + "." + cms.CompiledMethod.Name; poses.Add(pos); } else if (ss is CompiledPropertyScope) { pos.from_metadata = true; CompiledPropertyScope cps = ss as CompiledPropertyScope; pos.metadata_title = prepare_file_name(cps.CompiledProperty.DeclaringType.Name); pos.line = 1; pos.column = 1; pos.metadata_type = MetadataType.Property; if (!only_check) { pos.metadata = CodeCompletionController.CurrentParser.LanguageInformation.GetCompiledTypeRepresentation((ss as CompiledPropertyScope).CompiledProperty.DeclaringType, (ss as CompiledPropertyScope).CompiledProperty, ref pos.line, ref pos.column); Type t = cps.CompiledProperty.DeclaringType; int lines = 0; int ind = pos.metadata.IndexOf('\n'); pos.metadata = pos.metadata.Insert(ind + 1, get_references(t, out lines)); pos.line += lines; } pos.full_metadata_title = cps.CompiledProperty.DeclaringType.FullName + "." + cps.CompiledProperty.Name; poses.Add(pos); } else if (ss is CompiledConstructorScope) { CompiledConstructorScope ccs = ss as CompiledConstructorScope; pos.from_metadata = true; pos.line = 1; pos.column = 1; pos.metadata_title = prepare_file_name(ccs.CompiledConstructor.DeclaringType.Name); pos.metadata_type = MetadataType.Constructor; if (!only_check) { pos.metadata = CodeCompletionController.CurrentParser.LanguageInformation.GetCompiledTypeRepresentation(ccs.CompiledConstructor.DeclaringType, ccs.CompiledConstructor, ref pos.line, ref pos.column); Type t = ccs.CompiledConstructor.DeclaringType; int lines = 0; int ind = pos.metadata.IndexOf('\n'); pos.metadata = pos.metadata.Insert(ind + 1, get_references(t, out lines)); pos.line += lines; } pos.full_metadata_title = ccs.CompiledConstructor.DeclaringType.FullName + "." + ccs.CompiledConstructor.DeclaringType.Name; poses.Add(pos); } else if (ss is CompiledEventScope) { CompiledEventScope ces = ss as CompiledEventScope; pos.from_metadata = true; pos.line = 1; pos.column = 1; pos.metadata_title = prepare_file_name(ces.CompiledEvent.DeclaringType.Name); pos.metadata_type = MetadataType.Event; if (!only_check) { pos.metadata = CodeCompletionController.CurrentParser.LanguageInformation.GetCompiledTypeRepresentation(ces.CompiledEvent.DeclaringType, ces.CompiledEvent, ref pos.line, ref pos.column); Type t = ces.CompiledEvent.DeclaringType; int lines = 0; int ind = pos.metadata.IndexOf('\n'); pos.metadata = pos.metadata.Insert(ind + 1, get_references(t, out lines)); pos.line += lines; } pos.full_metadata_title = ces.CompiledEvent.DeclaringType.FullName + "." + ces.CompiledEvent.Name; poses.Add(pos); } else if (ss is NamespaceScope) { pos.from_metadata = true; pos.line = 1; pos.column = 1; pos.metadata_title = prepare_file_name((ss as NamespaceScope).name); pos.metadata_type = MetadataType.Event; pos.full_metadata_title = (ss as NamespaceScope).GetFullName(); poses.Add(pos); } } } catch(Exception e) { } RestoreCurrentUsedAssemblies(); return poses; }
/// <summary> /// Выдает все типы (используется после new) /// </summary> public SymInfo[] GetTypes(expression expr, int line, int col, out SymInfo out_si) { out_si = null; if (stv.cur_scope == null) return null; SymScope si = stv.FindScopeByLocation(line + 1, col + 1);//stv.cur_scope; SymInfo[] elems = null; if (si == null) return null; elems = si.GetNamesInAllTopScopes(true, new ExpressionVisitor(si, stv), false); if (expr != null) { ExpressionVisitor ev = new ExpressionVisitor(expr, si, stv); si = ev.GetScopeOfExpression(); if (si is TypeScope) si = new ElementScope(si); } List<SymInfo> result_names = new List<SymInfo>(); if (elems == null) return null; for (int i = 0; i < elems.Length; i++) { if (!elems[i].name.StartsWith("$") && (elems[i].kind == SymbolKind.Class || elems[i].kind == SymbolKind.Namespace) && elems[i].kind != SymbolKind.Interface) { if (expr != null && si != null && si is ElementScope && string.Compare(elems[i].name, (si as ElementScope).sc.si.name, true) == 0) { out_si = elems[i]; //out_si = new SymInfo(elems[i].name,elems[i].kind,elems[i].describe); string s = CodeCompletionController.CurrentParser.LanguageInformation.GetSimpleDescriptionWithoutNamespace((si as ElementScope).sc as PascalABCCompiler.Parsers.ITypeScope); if (s != out_si.name) out_si.addit_name = s; // if (((si as ElementScope).sc as TypeScope).TemplateArguments != null) // { // SymInfo tmp_si = new SymInfo(null,elems[i].kind,elems[i].describe); // StringBuilder sb = new StringBuilder(); // string[] template_args = ((si as ElementScope).sc as TypeScope).TemplateArguments; // sb.Append(elems[i].name); // sb.Append('<'); // for (int j=0; j<template_args.Length; j++) // { // sb.Append(template_args[j]); // if (j<template_args.Length-1) // sb.Append(','); // } // sb.Append('>'); // elems[i] = tmp_si; // out_si = tmp_si; // } } result_names.Add(elems[i]); } } if (out_si == null && expr != null && si != null && si is ElementScope) { out_si = (si as ElementScope).sc.si; if (!out_si.name.StartsWith("$") && out_si.kind != SymbolKind.Interface) { out_si.name = (si as ElementScope).sc.GetFullName(); result_names.Add(out_si); } else { out_si = null; } } return result_names.ToArray(); }
/// <summary> /// Получение описания символа /// </summary> public IBaseScope GetSymDefinition(expression expr, int line, int col, PascalABCCompiler.Parsers.KeywordKind keyword) { if (stv.cur_scope == null) return null; SymScope ss = stv.FindScopeByLocation(line + 1, col + 1);//stv.cur_scope; if (ss == null) return null; bool on_proc = false; if (keyword == PascalABCCompiler.Parsers.KeywordKind.Function || keyword == PascalABCCompiler.Parsers.KeywordKind.Constructor || keyword == PascalABCCompiler.Parsers.KeywordKind.Destructor) { if (ss is ProcRealization) { if (expr is ident) { if ((expr as ident).name == (ss as ProcRealization).def_proc.si.name) on_proc = true; } else on_proc = true; } else if (ss is ProcScope) { if (expr is ident) { if ((expr as ident).name == (ss as ProcScope).si.name) on_proc = true; } else on_proc = true; } } //if (!((keyword == KeywordKind.kw_proc || keyword == KeywordKind.kw_constr || keyword == KeywordKind.kw_destr) && ss is ProcScope)) if (!on_proc) { SetCurrentUsedAssemblies(); ExpressionVisitor ev = new ExpressionVisitor(expr, ss, stv); ss = ev.GetScopeOfExpression(); RestoreCurrentUsedAssemblies(); } return ss; }