Exemple #1
0
        public void GetSemanticExpansions(string filename, string tok, uint line, uint idx, string expr)
        {
            filename = normalizePath(filename);
            var ast = GetModule(filename);

            if (ast == null)
            {
                throw new COMException("module not found", 1);
            }

            _setupEditorData();
            CodeLocation loc = new CodeLocation((int)idx + 1, (int)line);

            _editorData.SyntaxTree  = ast as DModule;
            _editorData.ModuleCode  = _sources[filename];
            _editorData.CaretOffset = getCodeOffset(_editorData.ModuleCode, loc);
            // step back to beginning of identifier
            while (_editorData.CaretOffset > 0 && Lexer.IsIdentifierPart(_editorData.ModuleCode[_editorData.CaretOffset - 1]))
            {
                _editorData.CaretOffset--;
                if (idx > 0)
                {
                    idx--;
                }
            }
            _editorData.CaretLocation = new CodeLocation((int)idx + 1, (int)line);

            char triggerChar = string.IsNullOrEmpty(tok) ?  '\0' : tok[0];
            VDServerCompletionDataGenerator cdgen = new VDServerCompletionDataGenerator(tok);

            CodeCompletion.GenerateCompletionData(_editorData, cdgen, triggerChar);

            _expansions = cdgen.expansions;
        }
Exemple #2
0
        public static string GeneratePrototype(AbstractType t, int currentParameter = -1, bool isInTemplateArgInsight = false)
        {
            var ms = t as MemberSymbol;

            if (ms != null)
            {
                if (ms.Definition is DVariable)
                {
                    var bt = DResolver.StripAliasSymbol(ms.Base);
                    if (bt is DelegateType)
                    {
                        return(VDServerCompletionDataGenerator.GeneratePrototype(bt as DelegateType, currentParameter));
                    }
                }
                else if (ms.Definition is DMethod)
                {
                    return(VDServerCompletionDataGenerator.GeneratePrototype(ms.Definition as DMethod, isInTemplateArgInsight, currentParameter));
                }
            }
            else if (t is TemplateIntermediateType)
            {
                return(VDServerCompletionDataGenerator.GeneratePrototype(t as TemplateIntermediateType, currentParameter));
            }

            return(null);
        }
Exemple #3
0
        public void GetTip(string filename, int startLine, int startIndex, int endLine, int endIndex)
        {
            var ast = GetModule(filename);

            if (ast == null)
            {
                throw new COMException("module not found", 1);
            }

            _tipStart = new CodeLocation(startIndex + 1, startLine);
            _tipEnd   = new CodeLocation(startIndex + 2, startLine);
            _tipText.Clear();

            _setupEditorData();
            _editorData.CaretLocation = _tipStart;
            _editorData.SyntaxTree    = ast as DModule;
            _editorData.ModuleCode    = _sources[filename];
            // codeOffset+1 because otherwise it does not work on the first character
            _editorData.CaretOffset = getCodeOffset(_editorData.ModuleCode, _tipStart) + 1;

            DResolver.NodeResolutionAttempt attempt;
            var types = DResolver.ResolveTypeLoosely(_editorData, out attempt);

            _tipText.Clear();

            if (types != null)
            {
                if (types.DeclarationOrExpressionBase != null)
                {
                    _tipStart = types.DeclarationOrExpressionBase.Location;
                    _tipEnd   = types.DeclarationOrExpressionBase.EndLocation;
                }

                DNode dn = null;

                foreach (var t in AmbiguousType.TryDissolve(types))
                {
                    _tipText.Append(NodeToolTipContentGen.Instance.GenTooltipSignature(t)).Append("\a");
                    if (t is DSymbol)
                    {
                        dn = (t as DSymbol).Definition;
                    }
                }

                while (_tipText.Length > 0 && _tipText[_tipText.Length - 1] == '\a')
                {
                    _tipText.Length--;
                }

                if (dn != null)
                {
                    VDServerCompletionDataGenerator.GenerateNodeTooltipBody(dn, _tipText);
                }

                while (_tipText.Length > 0 && _tipText[_tipText.Length - 1] == '\a')
                {
                    _tipText.Length--;
                }
            }
        }
Exemple #4
0
        public void GetSemanticExpansions(string filename, string tok, uint line, uint idx, string expr)
        {
            DModule ast = null;

            if (!_modules.TryGetValue(filename, out ast))
            {
                throw new COMException("module not found", 1);
            }

            CodeLocation loc = new CodeLocation((int)idx + 1, (int)line);

            _editorData.SyntaxTree  = ast as DModule;
            _editorData.ModuleCode  = _sources[filename];
            _editorData.CaretOffset = getCodeOffset(_editorData.ModuleCode, loc);
            // step back to beginning of identifier
            while (_editorData.CaretOffset > 0 && isIdentifierCharacter(_editorData.ModuleCode[_editorData.CaretOffset - 1]))
            {
                _editorData.CaretOffset--;
                if (idx > 0)
                {
                    idx--;
                }
            }
            _editorData.CaretLocation = new CodeLocation((int)idx + 1, (int)line);

            VDServerCompletionDataGenerator cdgen    = new VDServerCompletionDataGenerator(tok);
            AbstractCompletionProvider      provider = AbstractCompletionProvider.BuildCompletionData(cdgen, _editorData, null);        //tok

            _expansions = cdgen.expansions;
        }
Exemple #5
0
        public static string GeneratePrototype(DelegateType dt, int currentParam = -1)
        {
            var dd = dt.TypeDeclarationOf as DelegateDeclaration;

            if (dd != null)
            {
                return(VDServerCompletionDataGenerator.GeneratePrototype(dd, currentParam));
            }

            return(null);
        }
Exemple #6
0
 // generate prototype
 public static string GeneratePrototype(INode node, int currentParameter = -1, bool isInTemplateArgInsight = false)
 {
     if (node is DMethod)
     {
         return(VDServerCompletionDataGenerator.GeneratePrototype(node as DMethod, isInTemplateArgInsight, currentParameter));
     }
     if (node is DVariable)
     {
         return(VDServerCompletionDataGenerator.GeneratePrototype(node as DVariable));
     }
     if (node is DelegateType)
     {
         return(VDServerCompletionDataGenerator.GeneratePrototype(node as DelegateType, currentParameter));
     }
     if (node is DelegateDeclaration)
     {
         return(VDServerCompletionDataGenerator.GeneratePrototype(node as DelegateDeclaration, currentParameter));
     }
     if (node is AbstractType)
     {
         return(VDServerCompletionDataGenerator.GeneratePrototype(node as AbstractType, currentParameter, isInTemplateArgInsight));
     }
     return(null);
 }
Exemple #7
0
        public void GetSemanticExpansions(string filename, string tok, uint line, uint idx, string expr)
		{
            filename = normalizePath(filename);
            var ast = GetModule(filename);

			if (ast == null)
				throw new COMException("module not found", 1);

			_setupEditorData();
			CodeLocation loc = new CodeLocation((int)idx + 1, (int) line);
			_editorData.SyntaxTree = ast as DModule;
			_editorData.ModuleCode = _sources[filename];
			_editorData.CaretOffset = getCodeOffset(_editorData.ModuleCode, loc);
			// step back to beginning of identifier
			while(_editorData.CaretOffset > 0 && Lexer.IsIdentifierPart(_editorData.ModuleCode[_editorData.CaretOffset-1]))
			{
				_editorData.CaretOffset--;
				if(idx > 0)
					idx--;
			}
			_editorData.CaretLocation = new CodeLocation((int)idx + 1, (int) line);

			char triggerChar = string.IsNullOrEmpty(tok) ?  '\0' : tok[0];
			VDServerCompletionDataGenerator cdgen = new VDServerCompletionDataGenerator(tok);
			CodeCompletion.GenerateCompletionData(_editorData, cdgen, triggerChar);

			_expansions = cdgen.expansions;
		}
Exemple #8
0
        public void GetTip(string filename, int startLine, int startIndex, int endLine, int endIndex)
        {
            filename = normalizePath(filename);
            var ast = GetModule(filename);

            if (ast == null)
            {
                throw new COMException("module not found", 1);
            }

            _tipStart = new CodeLocation(startIndex + 1, startLine);
            _tipEnd   = new CodeLocation(startIndex + 2, startLine);

            _request = Request.Tip;
            _result  = "__pending__";

            Action dg = () =>
            {
                _setupEditorData();
                _editorData.CaretLocation = _tipStart;
                _editorData.SyntaxTree    = ast as DModule;
                _editorData.ModuleCode    = _sources[filename];
                // codeOffset+1 because otherwise it does not work on the first character
                _editorData.CaretOffset = getCodeOffset(_editorData.ModuleCode, _tipStart) + 1;

                ISyntaxRegion sr = DResolver.GetScopedCodeObject(_editorData);
                LooseResolution.NodeResolutionAttempt attempt;
                AbstractType types = sr != null?LooseResolution.ResolveTypeLoosely(_editorData, sr, out attempt, true) : null;

                if (_editorData.CancelToken.IsCancellationRequested)
                {
                    return;
                }

                StringBuilder tipText = new StringBuilder();
                if (types != null)
                {
                    if (sr != null)
                    {
                        _tipStart = sr.Location;
                        _tipEnd   = sr.EndLocation;
                    }

                    DNode dn = null;

                    foreach (var t in AmbiguousType.TryDissolve(types))
                    {
                        tipText.Append(NodeToolTipContentGen.Instance.GenTooltipSignature(t)).Append("\a");
                        if (t is DSymbol)
                        {
                            dn = (t as DSymbol).Definition;
                        }
                    }

                    while (tipText.Length > 0 && tipText[tipText.Length - 1] == '\a')
                    {
                        tipText.Length--;
                    }

                    if (dn != null)
                    {
                        VDServerCompletionDataGenerator.GenerateNodeTooltipBody(dn, tipText);
                    }

                    while (tipText.Length > 0 && tipText[tipText.Length - 1] == '\a')
                    {
                        tipText.Length--;
                    }
                }
                if (_request == Request.Tip)
                {
                    _result = tipText.ToString();
                }
            };

            runAsync(dg);
        }
Exemple #9
0
        /// <summary>
        /// Adds a node to the completion data
        /// </summary>
        /// <param name="Node"></param>
        public void Add(INode Node)
        {
            string name = Node.Name;

            if (string.IsNullOrEmpty(name) || !name.StartsWith(prefix))
            {
                return;
            }

            string type = "I";             // Node.GetType().ToString()

            if (Node is DMethod)
            {
                type = "MTHD";
            }
            else if (Node is DClassLike)
            {
                var ctype = (Node as DClassLike).ClassType;
                if (ctype == DTokens.Struct)
                {
                    type = "STRU";
                }
                else if (ctype == DTokens.Class)
                {
                    type = "CLSS";
                }
                else if (ctype == DTokens.Interface)
                {
                    type = "IFAC";
                }
                else if (ctype == DTokens.Template)
                {
                    type = "TMPL";
                }
                else if (ctype == DTokens.Union)
                {
                    type = "UNIO";
                }
            }
            else if (Node is DEnum)
            {
                type = "ENUM";
            }
            else if (Node is DEnumValue)
            {
                type = "EVAL";
            }
            else if (Node is NamedTemplateMixinNode)
            {
                type = "NMIX";
            }
            else if (Node is DVariable)
            {
                type = "VAR";
            }
            else if (Node is DModule)
            {
                type = "MOD";
            }

            string desc  = Node.Description.Trim();
            string proto = VDServerCompletionDataGenerator.GeneratePrototype(Node);

            if (!string.IsNullOrEmpty(proto) && !string.IsNullOrEmpty(desc))
            {
                proto = proto + "\n\n";
            }
            desc = proto + desc;
            addExpansion(name, type, desc);
        }
Exemple #10
0
        public void GetSemanticExpansions(string filename, string tok, uint line, uint idx, string expr)
        {
            DModule ast = null;
            if (!_modules.TryGetValue(filename, out ast))
                throw new COMException("module not found", 1);

            _setupEditorData();
            CodeLocation loc = new CodeLocation((int)idx + 1, (int) line);
            _editorData.SyntaxTree = ast as DModule;
            _editorData.ModuleCode = _sources[filename];
            _editorData.CaretOffset = getCodeOffset(_editorData.ModuleCode, loc);
            // step back to beginning of identifier
            while(_editorData.CaretOffset > 0 && isIdentifierCharacter(_editorData.ModuleCode[_editorData.CaretOffset-1]))
            {
                _editorData.CaretOffset--;
                if(idx > 0)
                    idx--;
            }
            _editorData.CaretLocation = new CodeLocation((int)idx + 1, (int) line);

            VDServerCompletionDataGenerator cdgen = new VDServerCompletionDataGenerator(tok);
            AbstractCompletionProvider provider = AbstractCompletionProvider.BuildCompletionData(cdgen, _editorData, null); //tok

            _expansions = cdgen.expansions;
        }