Ejemplo n.º 1
0
                public override bool Matches(object actual)
                {
                    var code = actual as string;

                    if (code == null)
                    {
                        return(false);
                    }

                    code += "\n";

                    var m     = DParser.ParseString(code);
                    var cache = ResolutionTests.CreateCache();

                    (cache [0] as MutableRootPackage).AddModule(m);

                    var ed = new EditorData {
                        ModuleCode    = code,
                        CaretOffset   = code.Length - 1,
                        CaretLocation = DocumentHelper.OffsetToLocation(code, code.Length - 1),
                        SyntaxTree    = m,
                        ParseCache    = cache
                    };

                    var gen = new TestCompletionDataGen(null, null);
                    var res = CodeCompletion.GenerateCompletionData(ed, gen, 'a');

                    return(neg ? !res : res);
                }
Ejemplo n.º 2
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;
        }
Ejemplo n.º 3
0
        public static TestCompletionDataGen TestCompletionListContents(IEditorData ed, INode[] itemWhiteList = null, INode[] itemBlackList = null, char trigger = '\0')
        {
            var gen = new TestCompletionDataGen(itemWhiteList, itemBlackList);

            Assert.That(CodeCompletion.GenerateCompletionData(ed, gen, trigger), Is.True);

            Assert.That(gen.HasRemainingItems, Is.False, "Some items were not enlisted!");
            return(gen);
        }
Ejemplo n.º 4
0
        public static void BuildCompletionData(Document EditorDocument,
                                               DModule SyntaxTree,
                                               CodeCompletionContext ctx,
                                               CompletionDataList l,
                                               char triggerChar)
        {
            var ed = DResolverWrapper.CreateEditorData(EditorDocument, SyntaxTree, ctx, triggerChar);

            CodeCompletion.GenerateCompletionData(ed, new CompletionDataGenerator(l, null), triggerChar);
        }
Ejemplo n.º 5
0
        public void AutoCompletion()
        {
            var code = @"module A;
void main() {
auto 
}";
            var ed   = GenEditorData(3, 5, code);
            var g    = new TestCompletionDataGen(null, null);

            Assert.That(CodeCompletion.GenerateCompletionData(ed, g, 'a', true), Is.False);
        }
Ejemplo n.º 6
0
        public void ForeachCompletion()
        {
            var code = @"module A;
void main() {
foreach( 
}";
            var ed   = GenEditorData(3, 9, code);
            var g    = new TestCompletionDataGen(null, null);

            Assert.That(CodeCompletion.GenerateCompletionData(ed, g, 'a', true), Is.True);
        }
Ejemplo n.º 7
0
        public void NonStaticCompletion1()
        {
            var code = @"module A;
struct SomeStruct {ubyte a; static void read() {

}}
";
            var ed   = GenEditorData(3, 1, code);

            var SomeStruct = (ed.ParseCache [0] ["A"] ["SomeStruct"].First() as DClassLike);
            var a          = SomeStruct["a"].First() as DVariable;
            var read       = SomeStruct ["read"].First() as DMethod;
            var g          = new TestCompletionDataGen(new[] { read }, new[] { a });

            Assert.That(CodeCompletion.GenerateCompletionData(ed, g, '\0', true), Is.True);
        }
Ejemplo n.º 8
0
        public void ForeachIteratorCompletion()
        {
            var code = @"module A;
void main() {Cl** ii;
foreach(i;ii)
i.
}

struct Cl { int a; }
";
            var ed   = GenEditorData(4, 3, code);

            var a = (ed.ParseCache[0]["A"]["Cl"].First() as DClassLike)["a"].First() as DVariable;

            var g = new TestCompletionDataGen(new[] { a }, null);

            Assert.That(CodeCompletion.GenerateCompletionData(ed, g, 'a', true), Is.True);
        }
Ejemplo n.º 9
0
        protected override string Process(EditorData editorData, string tok)
        {
            var originalCaretLocation = editorData.CaretLocation;
            var idx = originalCaretLocation.Column - 1;

            // 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(idx + 1, originalCaretLocation.Line);

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

            var cdgen = new VDServerCompletionDataGenerator(tok);

            CodeCompletion.GenerateCompletionData(editorData, cdgen, triggerChar);
            return(cdgen.expansions.ToString());
        }
Ejemplo n.º 10
0
        public override Task <CompletionList> Handle(CompletionParams request, CancellationToken cancellationToken)
        {
            var ed       = CreateCompletionEditorData(request, cancellationToken, out char triggerChar);
            var workDone = ProgressManager.WorkDone(request,
                                                    new WorkDoneProgressBegin {
                Message = "Begin generating completion info", Percentage = 0
            });
            var progress = ProgressManager.For(request, cancellationToken);

            var allResults = new List <CompletionItem>();

            var completionDataGenerator = new CompletionDataGeneratorImpl(item =>
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    return;
                }

                allResults.Add(item);
                if (allResults.Count % 15 == 0)
                {
                    progress?.OnNext(new CompletionList(allResults));
                }
            });

            CodeCompletion.GenerateCompletionData(ed, completionDataGenerator, triggerChar);

            if (cancellationToken.IsCancellationRequested)
            {
                return(Task.FromCanceled <CompletionList>(cancellationToken));
            }
            workDone.OnCompleted();
            progress?.OnNext(new CompletionList(allResults));
            progress?.OnCompleted();

            return(Task.FromResult(progress != null ? new CompletionList() : new CompletionList(allResults)));
        }
Ejemplo n.º 11
0
        public void Process()
        {
            try
            {
                str               = File.ReadAllText(FullFilePath);
                this.FileLength   = str.Length;
                this.lengthString = this.FileLength.ToString();
                int line      = 1;
                int lineStart = 0;

                while (i <= str.Length)
                {
                    if (i < str.Length)
                    {
                        while (i < str.Length)
                        {
                            switch (str[i])
                            {
                            case ' ':
                            case '\t':
                                i++;
                                while (i < str.Length && (str[i] == ' ' || str[i] == '\t'))
                                {
                                    i++;
                                }
                                goto BreakLoop;

                            case '\n':
                                line++;
                                lineStart = i + 1;
                                i++;
                                continue;

                            case '"':
                                // Basic string
                                i++;
                                while (i < str.Length && str[i] != '"')
                                {
                                    if (str[i] == '\\')
                                    {
                                        i++;
                                    }
                                    i++;
                                }
                                i++;
                                goto BreakLoop;

                            case '/':
                                if (i + 1 >= str.Length)
                                {
                                    goto default;
                                }
                                if (str[i + 1] == '/')
                                {
                                    // Line Comment
                                    i += 2;
                                    while (i < str.Length && str[i] != '\n')
                                    {
                                        i++;
                                    }
                                    goto BreakLoop;
                                }
                                else if (str[i + 1] == '*')
                                {
                                    // Block Comment
                                    i += 2;
                                    while (i < str.Length)
                                    {
                                        if (str[i] == '*' && i + 1 < str.Length && str[i + 1] == '/')
                                        {
                                            i += 2;
                                            break;
                                        }
                                        else if (str[i] == '\n')
                                        {
                                            line++;
                                            lineStart = i + 1;
                                        }
                                        i++;
                                    }
                                    goto BreakLoop;
                                }
                                else if (str[i + 1] == '+')
                                {
                                    // Nesting Block Comment
                                    i += 2;
                                    int nestDepth = 1;
                                    while (i < str.Length)
                                    {
                                        if (str[i] == '+' && i + 1 < str.Length && str[i + 1] == '/')
                                        {
                                            i++;
                                            nestDepth--;
                                            if (nestDepth == 0)
                                            {
                                                i++;
                                                break;
                                            }
                                        }
                                        else if (str[i] == '/' && i + 1 < str.Length && str[i + 1] == '+')
                                        {
                                            i++;
                                            nestDepth++;
                                        }
                                        else if (str[i] == '\n')
                                        {
                                            line++;
                                            lineStart = i + 1;
                                        }
                                        i++;
                                    }
                                    goto BreakLoop;
                                }
                                goto default;

                            case '0':
                            case '1':
                            case '2':
                            case '3':
                            case '4':
                            case '5':
                            case '6':
                            case '7':
                            case '8':
                            case '9':
                                i++;
                                while (i < str.Length && IsDigit(str[i]))
                                {
                                    i++;
                                }
                                goto BreakLoop;

                            case 'a':
                            case 'b':
                            case 'c':
                            case 'd':
                            case 'e':
                            case 'f':
                            case 'g':
                            case 'h':
                            case 'i':
                            case 'j':
                            case 'k':
                            case 'l':
                            case 'm':
                            case 'n':
                            case 'o':
                            case 'p':
                            case 'q':
                            case 'r':
                            case 's':
                            case 't':
                            case 'u':
                            case 'v':
                            case 'w':
                            case 'x':
                            case 'y':
                            case 'z':
                            case 'A':
                            case 'B':
                            case 'C':
                            case 'D':
                            case 'E':
                            case 'F':
                            case 'G':
                            case 'H':
                            case 'I':
                            case 'J':
                            case 'K':
                            case 'L':
                            case 'M':
                            case 'N':
                            case 'O':
                            case 'P':
                            case 'Q':
                            case 'R':
                            case 'S':
                            case 'T':
                            case 'U':
                            case 'V':
                            case 'W':
                            case 'X':
                            case 'Y':
                            case 'Z':
                            case '_':
                                i++;
                                while (i < str.Length && (IsIdentifierChar(str[i]) || IsDigit(str[i])))
                                {
                                    i++;
                                }
                                goto BreakLoop;

                            default:
                                goto BreakLoop;
                            }
BreakLoop:
                            break;
                        }
                    }

                    string tStr;
                    if (i <= str.Length)
                    {
                        tStr = str.Substring(0, i);
                    }
                    else
                    {
                        tStr = str;
                    }
                    var ed = CompletionFacilities.GenEditorData(line, i - lineStart, tStr);
                    var g  = new SpecializedDataGen();
                    try
                    {
                        CodeCompletion.GenerateCompletionData(ed, g, 'a', true);
                    }
                    catch (OperationCanceledException)
                    {
                        TimeoutsTriggered.Add(i);
                    }
                    catch (Exception e)
                    {
                        ExceptionsTriggered.Add(new Tuple <int, string>(i, e.Message + "\r\nStack Trace:\r\n" + e.StackTrace));
                    }

                    i++;
                }
            }
            catch (Exception e)
            {
                if (!Directory.Exists(Program.TesterErrorsDirectory))
                {
                    Directory.CreateDirectory(Program.TesterErrorsDirectory);
                }
                File.WriteAllText(Program.TesterErrorsDirectory + "\\" + ShortFilePath.Replace('\\', '_') + "-" + i.ToString() + ".txt", e.Message + "\r\nStack Trace:\r\n" + e.StackTrace);
            }
        }