コード例 #1
0
        public void PartialScanning() {
            var code1 = "/* hello world ";
            var code2 = "   goodbye */";
            CollectingErrorSink errorSink = new CollectingErrorSink(true);
            var scanner = new JSScanner(code1, errorSink, new CodeSettings() { AllowShebangLine = true });
            var tokens = scanner.ReadTokens(Int32.MaxValue);
            VerifyTokens(
                tokens,
                new TokenInfo(JSToken.MultipleLineComment, new SourceLocation(0, 1, 1), new SourceLocation(15, 1, 16))
            );

            scanner.Initialize(code2, scanner.CurrentState, new SourceLocation(code1.Length, 2, 1));

            tokens = scanner.ReadTokens(Int32.MaxValue);
            VerifyTokens(
                tokens,
                new TokenInfo(JSToken.MultipleLineComment, new SourceLocation(15, 2, 16), new SourceLocation(28, 2, 29))
            );

            Assert.IsTrue(scanner.CurrentState.Equals(scanner.CurrentState));
            Assert.IsFalse(scanner.CurrentState.Equals(new object()));
            Assert.AreEqual(scanner.CurrentState.GetHashCode(), 2);
        }
コード例 #2
0
 private static List<TokenWithSpan> ReadTokens(string code, bool collectWarnings, params ErrorInfo[] errors) {
     CollectingErrorSink errorSink = new CollectingErrorSink(collectWarnings);
     var scanner = new JSScanner(code, errorSink, new CodeSettings() { AllowShebangLine = true });
     var tokens = scanner.ReadTokens(Int32.MaxValue);
     errorSink.CheckErrors(errors);
     return tokens;
 }
コード例 #3
0
 private static List<TokenWithSpan> ScanTokens(string code, bool collectWarnings, params ErrorInfo[] errors) {
     CollectingErrorSink errorSink = new CollectingErrorSink(collectWarnings);
     var scanner = new JSScanner(code, errorSink, new CodeSettings() { AllowShebangLine = true });
     List<TokenWithSpan> tokens = new List<TokenWithSpan>();
     for (TokenWithSpan curToken = scanner.ScanNextTokenWithSpan(true);
         curToken.Token != JSToken.EndOfFile;
         curToken = scanner.ScanNextTokenWithSpan(true)) {
         tokens.Add(curToken);
     }
     errorSink.CheckErrors(errors);
     return tokens;
 }
コード例 #4
0
        private void UpdateErrorsAndWarnings(
            IProjectEntry entry,
            ITextSnapshot snapshot,
            CollectingErrorSink errorSink
        ) {
            // There are some scenarios during ES6 Mode where a textview is still opened using NodeLS.
            // In these cases, we do not properly parse ES6 syntax, and therefore do not want to display errors. 
            if (NodejsPackage.Instance.IntellisenseOptionsPage.AnalysisLevel == AnalysisLevel.Preview) {
                return;
            }

            // Update the warn-on-launch state for this entry
            bool changed = false;
            lock (_hasParseErrors) {
                if (errorSink.Errors.Any() ? _hasParseErrors.Add(entry) : _hasParseErrors.Remove(entry)) {
                    changed = true;
                }
            }
            if (changed) {
                OnShouldWarnOnLaunchChanged(entry);
            }

            var f = new TaskProviderItemFactory(snapshot);

            // Update the parser warnings/errors
            if (errorSink.Warnings.Any() || errorSink.Errors.Any()) {
                TaskProvider.ReplaceItems(
                    entry,
                    ParserTaskMoniker,
                    errorSink.Warnings
                        .Where(ShouldIncludeWarning)
                        .Select(er => f.FromParseWarning(er))
                        .Concat(errorSink.Errors.Select(er => f.FromParseError(er)))
                        .ToList()
                );
            } else {
                TaskProvider.Clear(entry, ParserTaskMoniker);
            }
#if FALSE
            // Add a handler for the next complete analysis
            _unresolvedSquiggles.ListenForNextNewAnalysis(entry as IJsProjectEntry);
#endif
        }
コード例 #5
0
        private void ParseNodejsCode(TextReader content, out JsAst ast, out CollectingErrorSink errorSink) {
            ast = null;
            errorSink = new CollectingErrorSink();

            var parser = CreateParser(content, errorSink);
            ast = ParseOneFile(ast, parser);
        }
コード例 #6
0
        private void UpdateErrorsAndWarnings(
            IProjectEntry entry,
            ITextSnapshot snapshot,
            CollectingErrorSink errorSink
        ) {
            // Update the warn-on-launch state for this entry
            bool changed = false;
            lock (_hasParseErrors) {
                if (errorSink.Errors.Any() ? _hasParseErrors.Add(entry) : _hasParseErrors.Remove(entry)) {
                    changed = true;
                }
            }
            if (changed) {
                OnShouldWarnOnLaunchChanged(entry);
            }

            var f = new TaskProviderItemFactory(snapshot);

            // Update the parser warnings/errors
            if (errorSink.Warnings.Any() || errorSink.Errors.Any()) {
                TaskProvider.ReplaceItems(
                    entry,
                    ParserTaskMoniker,
                    errorSink.Warnings
                        .Where(ShouldIncludeWarning)
                        .Select(er => f.FromParseWarning(er))
                        .Concat(errorSink.Errors.Select(er => f.FromParseError(er)))
                        .ToList()
                );
            } else {
                TaskProvider.Clear(entry, ParserTaskMoniker);
            }
#if FALSE
            // Add a handler for the next complete analysis
            _unresolvedSquiggles.ListenForNextNewAnalysis(entry as IJsProjectEntry);
#endif
        }