public static void BuildCompletionData(Document EditorDocument, IAbstractSyntaxTree SyntaxTree, CodeCompletionContext ctx, CompletionDataList l, char triggerChar) { bool removeChar = char.IsLetter(triggerChar) || triggerChar == '_' || triggerChar == '@'; var deltaOffset = 0; //removeChar ? 1 : 0; var caretOffset = ctx.TriggerOffset - (removeChar ? 1 : 0); var caretLocation = new CodeLocation(ctx.TriggerLineOffset - deltaOffset, ctx.TriggerLine); var codeCache = EnumAvailableModules(EditorDocument); var ed = new EditorData { CaretLocation = caretLocation, CaretOffset = caretOffset, ModuleCode = removeChar ? EditorDocument.Editor.Text.Remove(ctx.TriggerOffset - 1, 1) : EditorDocument.Editor.Text, SyntaxTree = SyntaxTree as DModule, ParseCache = codeCache, Options = DCompilerService.Instance.CompletionOptions }; if (EditorDocument.HasProject) { var cfg = EditorDocument.Project.GetConfiguration(Ide.IdeApp.Workspace.ActiveConfiguration) as DProjectConfiguration; if (cfg != null) { ed.GlobalDebugIds = cfg.CustomDebugIdentifiers; ed.IsDebug = cfg.DebugMode; ed.DebugLevel = cfg.DebugLevel; ed.GlobalVersionIds = cfg.GlobalVersionIdentifiers; double d; int v; if (Double.TryParse(EditorDocument.Project.Version, out d)) { ed.VersionNumber = (int)d; } else if (Int32.TryParse(EditorDocument.Project.Version, out v)) { ed.VersionNumber = v; } } } if (ed.GlobalVersionIds == null) { ed.GlobalVersionIds = VersionIdEvaluation.GetOSAndCPUVersions(); } AbstractCompletionProvider.BuildCompletionData( new CompletionDataGenerator { CompletionDataList = l }, ed, triggerChar == '\0'?null:triggerChar.ToString()); }
public static EditorData CreateEditorData(Document EditorDocument, DModule Ast, CodeCompletionContext ctx, char triggerChar = '\0') { bool removeChar = char.IsLetter(triggerChar) || triggerChar == '_' || triggerChar == '@'; var deltaOffset = 0; //removeChar ? 1 : 0; var caretOffset = ctx.TriggerOffset - (removeChar ? 1 : 0); var caretLocation = new CodeLocation(ctx.TriggerLineOffset - deltaOffset, ctx.TriggerLine); var codeCache = CreateCacheList(EditorDocument); var ed = new EditorData { CaretLocation = caretLocation, CaretOffset = caretOffset, ModuleCode = removeChar ? EditorDocument.Editor.Text.Remove(ctx.TriggerOffset - 1, 1) : EditorDocument.Editor.Text, SyntaxTree = Ast, ParseCache = codeCache }; if (EditorDocument.HasProject) { var cfg = EditorDocument.Project.GetConfiguration(Ide.IdeApp.Workspace.ActiveConfiguration) as DProjectConfiguration; if (cfg != null) { ed.GlobalDebugIds = cfg.CustomDebugIdentifiers; ed.IsDebug = cfg.DebugMode; ed.DebugLevel = cfg.DebugLevel; ed.GlobalVersionIds = cfg.GlobalVersionIdentifiers; double d; int v; if (Double.TryParse(EditorDocument.Project.Version, out d)) { ed.VersionNumber = (int)d; } else if (Int32.TryParse(EditorDocument.Project.Version, out v)) { ed.VersionNumber = v; } } } if (ed.GlobalVersionIds == null) { ed.GlobalVersionIds = VersionIdEvaluation.GetOSAndCPUVersions(); } return(ed); }
public static ResolutionContext CreateContext(Document doc, bool pushFirstScope = true) { if (doc != null) { var ed = DResolverWrapper.CreateEditorData(doc); if (pushFirstScope) { return(new ResolutionContext(ed.ParseCache, new ConditionalCompilationFlags(ed), ed.SyntaxTree, ed.CaretLocation)); } return(new ResolutionContext(ed.ParseCache, new ConditionalCompilationFlags(ed))); } return(new ResolutionContext(DResolverWrapper.CreateParseCacheView(), new ConditionalCompilationFlags(VersionIdEvaluation.GetOSAndCPUVersions(), 1, true))); }
public static EditorData CreateEditorData(TextDocumentPositionParams documentPositionParams, CancellationToken cancellationToken) { var module = TextDocumentHandler.GetAstModule(documentPositionParams.TextDocument.Uri); var code = TextDocumentHandler.GetModuleCode(documentPositionParams.TextDocument.Uri); var caret = new CodeLocation((int)documentPositionParams.Position.Character + 1, (int)documentPositionParams.Position.Line + 1); return(new EditorData { ParseCache = CreateParseCacheView(), CancelToken = cancellationToken, CaretLocation = caret, CaretOffset = DocumentHelper.LocationToOffset(code, caret), ModuleCode = code, SyntaxTree = module, GlobalVersionIds = VersionIdEvaluation.GetOSAndCPUVersions() }); }
public static ResolutionContext CreateCurrentContext() { Document doc = null; DispatchService.GuiSyncDispatch(() => doc = Ide.IdeApp.Workbench.ActiveDocument); if (doc != null) { var ddoc = doc.ParsedDocument as ParsedDModule; if (ddoc != null) { var ast = ddoc.DDom; if (ast != null) { IStatement stmt; var caret = new D_Parser.Dom.CodeLocation(doc.Editor.Caret.Column, doc.Editor.Caret.Line); var bn = DResolver.SearchBlockAt(ast, caret, out stmt); var dbn = bn as DBlockNode; if (stmt == null && dbn != null) { //TODO: If inside an expression statement, search the nearest function call or template instance expression - and try to evaluate that one. if (dbn.StaticStatements.Count != 0) { foreach (var ss in dbn.StaticStatements) { if (caret >= ss.Location && caret <= ss.EndLocation) { stmt = ss; break; } } } } var ed = DResolverWrapper.CreateEditorData(doc); return(new ResolutionContext(ed.ParseCache, new ConditionalCompilationFlags(ed), bn, stmt)); } } } return(new ResolutionContext(DResolverWrapper.CreateCacheList(), new ConditionalCompilationFlags(VersionIdEvaluation.GetOSAndCPUVersions(), 1, true), null)); }
public static ResolutionContext CreateContext(Document doc, bool pushFirstScope = true) { if (doc != null) { var ddoc = doc.ParsedDocument as ParsedDModule; if (ddoc != null) { var ast = ddoc.DDom; if (ast != null) { var ed = DResolverWrapper.CreateEditorData(doc); if (pushFirstScope) { return(new ResolutionContext(ed.ParseCache, new ConditionalCompilationFlags(ed), ast, ed.CaretLocation)); } return(new ResolutionContext(ed.ParseCache, new ConditionalCompilationFlags(ed))); } } } return(new ResolutionContext(DResolverWrapper.CreateCacheList(), new ConditionalCompilationFlags(VersionIdEvaluation.GetOSAndCPUVersions(), 1, true))); }
public static EditorData CreateEditorData(Document EditorDocument, DModule Ast, CodeCompletionContext ctx, char triggerChar = '\0') { bool removeChar = char.IsLetter(triggerChar) || triggerChar == '_'; var deltaOffset = 0; //removeChar ? 1 : 0; var caretOffset = ctx.TriggerOffset - (removeChar ? 1 : 0); var caretLocation = new CodeLocation(ctx.TriggerLineOffset - deltaOffset, ctx.TriggerLine); var codeCache = CreateParseCacheView(EditorDocument); var ed = new EditorData { CaretLocation = caretLocation, CaretOffset = caretOffset, ModuleCode = removeChar ? EditorDocument.Editor.Text.Remove(ctx.TriggerOffset - 1, 1) : EditorDocument.Editor.Text, SyntaxTree = Ast, ParseCache = codeCache }; if (EditorDocument.HasProject) { var versions = new List <string>(); var debugConstants = new List <string> (); var cfg = EditorDocument.Project.GetConfiguration(IdeApp.Workspace.ActiveConfiguration); if (cfg is DProjectConfiguration) { var dcfg = cfg as DProjectConfiguration; ed.IsDebug = dcfg.DebugMode; ed.DebugLevel = dcfg.DebugLevel; double d; ulong v; if (Double.TryParse(EditorDocument.Project.Version, out d)) { ed.VersionNumber = (ulong)d; } else if (UInt64.TryParse(EditorDocument.Project.Version, out v)) { ed.VersionNumber = v; } } else if (cfg is DubProjectConfiguration) { versions.AddRange(VersionIdEvaluation.GetOSAndCPUVersions()); var dcfg = cfg as DubProjectConfiguration; ed.IsDebug = dcfg.DebugMode; } foreach (var prj in GetProjectDependencyHierarchyToCurrentStartupProject(EditorDocument.Project, cfg.Selector)) { if (prj is AbstractDProject) { ExtractVersionDebugConstantsFromProject(prj as AbstractDProject, versions, debugConstants); } } ed.GlobalDebugIds = debugConstants.ToArray(); ed.GlobalVersionIds = versions.ToArray(); } if (ed.GlobalVersionIds == null || ed.GlobalVersionIds.Length == 0) { ed.GlobalVersionIds = VersionIdEvaluation.GetOSAndCPUVersions(); } return(ed); }