Exemplo n.º 1
0
        public void Analyze(CancellationToken cancel)
        {
            if (cancel.IsCancellationRequested)
            {
                return;
            }

            lock (this) {
                if (_analysis == null)
                {
                    _analysis = new XamlAnalysis(_filename);
                    _cookie   = new FileCookie(_filename);
                }
                _analysis = new XamlAnalysis(new StringReader(_content));

                _version++;

                // update any .py files which depend upon us.
                for (var deps = GetNewDependencies(null); deps.Any(); deps = GetNewDependencies(deps))
                {
                    foreach (var dep in deps)
                    {
                        dep.Analyze(cancel);
                    }
                }
            }
        }
 internal ProjectEntry(JsAnalyzer analyzer, string filePath, IAnalysisCookie cookie, bool isBuiltin = false) {
     _analyzer = analyzer;
     _filePath = filePath;
     _cookie = cookie;
     _moduleRecord = new ModuleEnvironmentRecord(this);
     _isBuiltin = isBuiltin;
 }
Exemplo n.º 3
0
        internal ProjectEntry(
            PythonAnalyzer state,
            string moduleName,
            string filePath,
            Uri documentUri,
            IAnalysisCookie cookie
            )
        {
            ProjectState = state;
            ModuleName   = moduleName ?? "";
            DocumentUri  = documentUri ?? MakeDocumentUri(filePath);
            FilePath     = filePath;
            Cookie       = cookie;

            MyScope = new ModuleInfo(ModuleName, this, state.Interpreter.CreateModuleContext());
            _unit   = new AnalysisUnit(null, MyScope.Scope);

            _buffers = new SortedDictionary <int, DocumentBuffer> {
                [0] = new DocumentBuffer()
            };
            if (Cookie is InitialContentCookie c)
            {
                _buffers[0].Reset(c.Version, c.Content);
            }
            AnalysisLog.NewUnit(_unit);
        }
Exemplo n.º 4
0
        public override async Task DidOpenTextDocument(DidOpenTextDocumentParams @params)
        {
            TraceMessage($"Opening document {@params.textDocument.uri}");

            var entry = _projectFiles.GetEntry(@params.textDocument.uri, throwIfMissing: false);
            var doc   = entry as IDocument;

            if (doc != null)
            {
                if (@params.textDocument.text != null)
                {
                    doc.ResetDocument(@params.textDocument.version, @params.textDocument.text);
                }
            }
            else if (entry == null)
            {
                IAnalysisCookie cookie = null;
                if (@params.textDocument.text != null)
                {
                    cookie = new InitialContentCookie {
                        Content = @params.textDocument.text,
                        Version = @params.textDocument.version
                    };
                }
                entry = await AddFileAsync(@params.textDocument.uri, null, cookie);
            }

            if ((doc = entry as IDocument) != null)
            {
                EnqueueItem(doc);
            }
        }
Exemplo n.º 5
0
 public void GetTreeAndCookie(out SourceUnitTree tree, out IAnalysisCookie cookie)
 {
     lock (this) {
         tree   = _node;
         cookie = _curCookie;
     }
 }
Exemplo n.º 6
0
        public override async Task DidOpenTextDocument(DidOpenTextDocumentParams @params, CancellationToken token)
        {
            _disposableBag.ThrowIfDisposed();
            TraceMessage($"Opening document {@params.textDocument.uri}");

            _editorFiles.Open(@params.textDocument.uri);
            var entry = ProjectFiles.GetEntry(@params.textDocument.uri, throwIfMissing: false);
            var doc   = entry as IDocument;

            if (doc != null)
            {
                if (@params.textDocument.text != null)
                {
                    doc.ResetDocument(@params.textDocument.version, @params.textDocument.text);
                }
                await EnqueueItemAsync(doc);
            }
            else if (entry == null)
            {
                IAnalysisCookie cookie = null;
                if (@params.textDocument.text != null)
                {
                    cookie = new InitialContentCookie {
                        Content = @params.textDocument.text,
                        Version = @params.textDocument.version
                    };
                }
                entry = await AddFileAsync(@params.textDocument.uri, cookie);
            }
        }
Exemplo n.º 7
0
 public void GetTreeAndCookie(out PythonAst tree, out IAnalysisCookie cookie)
 {
     lock (this) {
         tree   = _tree;
         cookie = _cookie;
     }
 }
Exemplo n.º 8
0
        public void UpdateTree(PythonAst newAst, IAnalysisCookie newCookie)
        {
            lock (this) {
                if (_updatesPending > 0)
                {
                    _updatesPending--;
                }
                if (newAst == null)
                {
                    // there was an error in parsing, just let the waiter go...
                    if (_curWaiter != null)
                    {
                        _curWaiter.Set();
                    }
                    _tree = null;
                    return;
                }

                _tree   = newAst;
                _cookie = newCookie;

                if (_curWaiter != null)
                {
                    _curWaiter.Set();
                }
            }

            var newParse = OnNewParseTree;

            if (newParse != null)
            {
                newParse(this, EventArgs.Empty);
            }
        }
Exemplo n.º 9
0
        public void UpdateTree(PythonAst newAst, IAnalysisCookie newCookie) {
            lock (this) {
                if (_updatesPending > 0) {
                    _updatesPending--;
                }
                if (newAst == null) {
                    // there was an error in parsing, just let the waiter go...
                    if (_curWaiter != null) {
                        _curWaiter.Set();
                    }
                    _tree = null;
                    return;
                }

                _tree = newAst;
                _cookie = newCookie;

                if (_curWaiter != null) {
                    _curWaiter.Set();
                }
            }

            var newParse = OnNewParseTree;
            if (newParse != null) {
                newParse(this, EventArgs.Empty);
            }
        }
Exemplo n.º 10
0
 public void SetCurrentParse(PythonAst tree, IAnalysisCookie cookie)
 {
     lock (this) {
         Tree   = tree;
         Cookie = cookie;
     }
     OnNewParseTree?.Invoke(this, EventArgs.Empty);
 }
Exemplo n.º 11
0
        public IXamlProjectEntry AddXamlFile(string filePath, IAnalysisCookie cookie = null)
        {
            var entry = new XamlProjectEntry(filePath);

            _xamlByFilename[filePath] = entry;

            return(entry);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Adds a new module of code to the list of available modules and returns a ProjectEntry object.
        ///
        /// This method is thread safe.
        /// </summary>
        /// <param name="moduleName">The name of the module; used to associate with imports</param>
        /// <param name="filePath">The path to the file on disk</param>
        /// <param name="cookie">An application-specific identifier for the module</param>
        /// <returns></returns>
        public ProjectEntry AddModule(string filePath, IAnalysisCookie cookie = null)
        {
            var entry = new ProjectEntry(this, filePath, cookie);

            Modules.AddModule(filePath, entry);

            return(entry);
        }
Exemplo n.º 13
0
 internal ProjectEntry(JsAnalyzer analyzer, string filePath, IAnalysisCookie cookie, bool isBuiltin = false)
 {
     _analyzer     = analyzer;
     _filePath     = filePath;
     _cookie       = cookie;
     _moduleRecord = new ModuleEnvironmentRecord(this);
     _isBuiltin    = isBuiltin;
 }
Exemplo n.º 14
0
 internal ProjectEntry(PythonAnalyzer state, string moduleName, string filePath, IAnalysisCookie cookie)
 {
     _projectState = state;
     _moduleName   = moduleName ?? "";
     _filePath     = filePath;
     _cookie       = cookie;
     _myScope      = new ModuleInfo(_moduleName, this, state.Interpreter.CreateModuleContext());
     _unit         = new AnalysisUnit(_tree, new InterpreterScope[] { _myScope.Scope });
 }
Exemplo n.º 15
0
 internal ProjectEntry(PythonAnalyzer state, string moduleName, string filePath, IAnalysisCookie cookie) {
     _projectState = state;
     _moduleName = moduleName ?? "";
     _filePath = filePath;
     _cookie = cookie;
     _myScope = new ModuleInfo(_moduleName, this, state.Interpreter.CreateModuleContext());
     _unit = new AnalysisUnit(_tree, _myScope.Scope);
     AnalysisLog.NewUnit(_unit);
 }
Exemplo n.º 16
0
 internal GeneroProjectEntry(string moduleName, string filePath, IAnalysisCookie cookie, bool shouldAnalyzeDir)
 {
     _moduleName = moduleName ?? "";
     _filePath   = filePath;
     _cookie     = cookie;
     //_shouldAnalyzeDir = shouldAnalyzeDir;
     //_myScope = new ModuleInfo(_moduleName, this, state.Interpreter.CreateModuleContext());
     //_unit = new AnalysisUnit(_tree, _myScope.Scope);
     //AnalysisLog.NewUnit(_unit);
 }
Exemplo n.º 17
0
 public void SetCurrentParse(PythonAst tree, IAnalysisCookie cookie, bool notify = true)
 {
     lock (this) {
         Tree   = tree;
         Cookie = cookie;
     }
     if (notify)
     {
         NewParseTree?.Invoke(this, EventArgs.Empty);
     }
 }
Exemplo n.º 18
0
        private IProjectEntry CreateProjectEntry(ITextBuffer buffer, IAnalysisCookie analysisCookie)
        {
            var replEval = buffer.GetReplEvaluator();

            if (replEval != null)
            {
                // We have a repl window, create an untracked module.
                return(_analysisState.AddModule(null, null, analysisCookie));
            }

            string path = buffer.GetFilePath();

            if (path == null)
            {
                return(null);
            }

            IProjectEntry entry;

            if (!_projectFiles.TryGetValue(path, out entry))
            {
                var modName = PythonAnalyzer.PathToModuleName(path);

                if (buffer.ContentType.IsOfType(PythonCoreConstants.ContentType))
                {
                    entry = _analysisState.AddModule(
                        modName,
                        buffer.GetFilePath(),
                        analysisCookie
                        );
                }
                else if (buffer.ContentType.IsOfType("XAML"))
                {
                    entry = _analysisState.AddXamlFile(buffer.GetFilePath());
                }
                else
                {
                    return(null);
                }

                _projectFiles[path] = entry;

                if (ImplicitProject &&
                    !Path.GetFullPath(path).StartsWith(Path.GetDirectoryName(_interpreterFactory.Configuration.InterpreterPath), StringComparison.OrdinalIgnoreCase))   // don't analyze std lib
                // TODO: We're doing this on the UI thread and when we end up w/ a lot to queue here we hang for a while...
                // But this adds files to the analyzer so it's not as simple as queueing this onto another thread.
                {
                    AddImplicitFiles(Path.GetDirectoryName(Path.GetFullPath(path)));
                }
            }

            return(entry);
        }
Exemplo n.º 19
0
        internal ProjectEntry(ProjectState state, string moduleName, string filePath, IAnalysisCookie cookie)
        {
            Debug.Assert(moduleName != null);
            Debug.Assert(filePath != null);

            _projectState = state;
            _moduleName   = moduleName ?? "";
            _filePath     = filePath;
            _cookie       = cookie;
            _myScope      = new ModuleInfo(_moduleName, this);
            _unit         = new AnalysisUnit(_tree, new InterpreterScope[] { _myScope.Scope }, null);
        }
Exemplo n.º 20
0
        public void UpdateTree(SourceUnitTree newAst, IAnalysisCookie newCookie)
        {
            lock (this) {
                _node      = newAst;
                _curCookie = newCookie;
            }
            var newParse = OnNewParseTree;

            if (newParse != null)
            {
                newParse(this, EventArgs.Empty);
            }
        }
Exemplo n.º 21
0
        public void UpdateTree(PythonAst newAst, IAnalysisCookie newCookie)
        {
            lock (this) {
                _tree   = newAst;
                _cookie = newCookie;
            }

            var newParse = OnNewParseTree;

            if (newParse != null)
            {
                newParse(this, EventArgs.Empty);
            }
        }
Exemplo n.º 22
0
        /// <summary>
        /// Adds a new module of code to the list of available modules and returns a ProjectEntry object.
        /// </summary>
        /// <param name="moduleName">The name of the module; used to associate with imports</param>
        /// <param name="filePath">The path to the file on disk</param>
        /// <param name="cookie">An application-specific identifier for the module</param>
        /// <returns></returns>
        public IPythonProjectEntry AddModule(string moduleName, string filePath, IAnalysisCookie cookie = null)
        {
            var entry = new ProjectEntry(this, moduleName, filePath, cookie);

            if (moduleName != null)
            {
                Modules[moduleName] = new ModuleReference(entry.MyScope);
            }
            if (filePath != null)
            {
                _modulesByFilename[filePath] = entry.MyScope;
            }
            return(entry);
        }
Exemplo n.º 23
0
        /// <summary>
        /// Adds a new module of code to the list of available modules and returns a ProjectEntry object.
        ///
        /// This method is thread safe.
        /// </summary>
        /// <param name="moduleName">The name of the module; used to associate with imports</param>
        /// <param name="filePath">The path to the file on disk</param>
        /// <param name="cookie">An application-specific identifier for the module</param>
        /// <returns>The project entry for the new module.</returns>
        public IPythonProjectEntry AddModule(string moduleName, string filePath, IAnalysisCookie cookie = null)
        {
            var entry = new ProjectEntry(this, moduleName, filePath, cookie);

            if (moduleName != null)
            {
                var moduleRef = Modules.GetOrAdd(moduleName);
                moduleRef.Module = entry.MyScope;

                DoDelayedSpecialization(moduleName);
            }
            if (filePath != null)
            {
                _modulesByFilename[filePath] = entry.MyScope;
            }
            return(entry);
        }
Exemplo n.º 24
0
        private async Task <IProjectEntry> AddFileAsync(Uri documentUri, IAnalysisCookie cookie = null)
        {
            var item = ProjectFiles.GetEntry(documentUri, throwIfMissing: false);

            if (item != null)
            {
                return(item);
            }

            var path    = GetLocalPath(documentUri);
            var aliases = GetImportNames(documentUri).Select(mp => mp.ModuleName).ToArray();

            if (aliases.Length == 0)
            {
                aliases = new[] { Path.GetFileNameWithoutExtension(path) };
            }

            var first = aliases.First();

            var pyItem = Analyzer.AddModule(first, path, documentUri, cookie);

            item = pyItem;

            var actualItem = ProjectFiles.GetOrAddEntry(documentUri, item);

            if (actualItem != item)
            {
                return(actualItem);
            }

            var reanalyzeEntries = Analyzer.GetEntriesThatImportModule(pyItem.ModuleName, true).ToArray();

            pyItem.NewAnalysis += OnProjectEntryNewAnalysis;

            if (item is IDocument doc)
            {
                await EnqueueItemAsync(doc);
            }

            foreach (var entryRef in reanalyzeEntries)
            {
                await EnqueueItemAsync(entryRef as IDocument, AnalysisPriority.Low, parse : false);
            }

            return(item);
        }
Exemplo n.º 25
0
        public void Analyze()
        {
            lock (this) {
                if (_analysis == null)
                {
                    _analysis = new XamlAnalysis(_filename);
                    _cookie   = new FileCookie(_filename);
                }
                _analysis = new XamlAnalysis(_content);

                _version++;

                // update any .py files which depend upon us.
                foreach (var dep in _dependencies)
                {
                    dep.Analyze();
                }
            }
        }
Exemplo n.º 26
0
        /// <summary>
        /// Parses the specified file on disk.
        /// </summary>
        /// <param name="filename"></param>
        public void EnqueueFile(IProjectEntry projEntry, string filename)
        {
            var severity = Severity.Ignore;

            EnqueWorker(() =>
            {
                for (int i = 0; i < 10; i++)
                {
                    try
                    {
                        if (!File.Exists(filename))
                        {
                            break;
                        }
                        using (var reader = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete))
                        {
                            _parser.ParseFile(projEntry, filename, reader, severity);
                            return;
                        }
                    }
                    catch (IOException)
                    {
                        // file being copied, try again...
                        Thread.Sleep(100);
                    }
                    catch (UnauthorizedAccessException)
                    {
                        // file is inaccessible, try again...
                        Thread.Sleep(100);
                    }
                }

                IGeneroProjectEntry gEntry = projEntry as IGeneroProjectEntry;
                IAnalysisCookie cookie     = null;
                Genero4glAst node          = null;
                if (gEntry != null)
                {
                    // failed to parse, keep the UpdateTree calls balanced
                    gEntry.UpdateTree(node, cookie);
                }
            });
        }
Exemplo n.º 27
0
        public void Analyze(CancellationToken cancel) {
            if (cancel.IsCancellationRequested) {
                return;
            }

            lock (this) {
                if (_analysis == null) {
                    _analysis = new XamlAnalysis(_filename);
                    _cookie = new FileCookie(_filename);
                }
                _analysis = new XamlAnalysis(new StringReader(_content));

                _version++;

                // update any .py files which depend upon us.
                for (var deps = GetNewDependencies(null); deps.Any(); deps = GetNewDependencies(deps)) {
                    foreach (var dep in deps) {
                        dep.Analyze(cancel);
                    }
                }
            }
        }
Exemplo n.º 28
0
 public void UpdateContent(TextReader content, IAnalysisCookie fileCookie)
 {
     _content = content;
     _cookie = fileCookie;
 }
Exemplo n.º 29
0
        public void Analyze()
        {
            lock (this) {
                if (_analysis == null) {
                    _analysis = new XamlAnalysis(_filename);
                    _cookie = new FileCookie(_filename);
                }
                _analysis = new XamlAnalysis(_content);

                _version++;

                // update any .py files which depend upon us.
                foreach (var dep in _dependencies) {
                    dep.Analyze();
                }
            }
        }
Exemplo n.º 30
0
        public void UpdateTree(PythonAst newAst, IAnalysisCookie newCookie)
        {
            lock (this) {
                _tree = newAst;
                _cookie = newCookie;
            }

            var newParse = OnNewParseTree;
            if (newParse != null) {
                newParse(this, EventArgs.Empty);
            }
        }
Exemplo n.º 31
0
        internal ProjectEntry(ProjectState state, string moduleName, string filePath, IAnalysisCookie cookie)
        {
            Debug.Assert(moduleName != null);
            Debug.Assert(filePath != null);

            _projectState = state;
            _moduleName = moduleName ?? "";
            _filePath = filePath;
            _cookie = cookie;
            _myScope = new ModuleInfo(_moduleName, this);
            _unit = new AnalysisUnit(_tree, new InterpreterScope[] { _myScope.Scope }, null);
        }
Exemplo n.º 32
0
 internal ModuleAnalysis(AnalysisUnit unit, ModuleEnvironmentRecord scope, IAnalysisCookie cookie) {
     _unit = unit;
     _scope = scope;
     _cookie = cookie;
 }
Exemplo n.º 33
0
 public void GetTreeAndCookie(out PythonAst tree, out IAnalysisCookie cookie)
 {
     lock (this) {
         tree = _tree;
         cookie = _cookie;
     }
 }
Exemplo n.º 34
0
 internal ModuleAnalysis(AnalysisUnit unit, ModuleEnvironmentRecord scope, IAnalysisCookie cookie)
 {
     _unit   = unit;
     _scope  = scope;
     _cookie = cookie;
 }
Exemplo n.º 35
0
        private async Task <IProjectEntry> AddFileAsync(Uri documentUri, Uri fromSearchPath, IAnalysisCookie cookie = null)
        {
            var item = ProjectFiles.GetEntry(documentUri, throwIfMissing: false);

            if (item != null)
            {
                return(item);
            }

            string[] aliases = null;
            var      path    = GetLocalPath(documentUri);

            if (fromSearchPath != null)
            {
                if (ModulePath.FromBasePathAndFile_NoThrow(GetLocalPath(fromSearchPath), path, out var mp))
                {
                    aliases = new[] { mp.ModuleName };
                }
            }
            else
            {
                aliases = GetImportNames(documentUri).Select(mp => mp.ModuleName).ToArray();
            }

            if (aliases.IsNullOrEmpty())
            {
                aliases = new[] { Path.GetFileNameWithoutExtension(path) };
            }

            var reanalyzeEntries = aliases.SelectMany(a => Analyzer.GetEntriesThatImportModule(a, true)).ToArray();
            var first            = aliases.FirstOrDefault();

            var pyItem = Analyzer.AddModule(first, path, documentUri, cookie);

            item = pyItem;
            foreach (var a in aliases.Skip(1))
            {
                Analyzer.AddModuleAlias(first, a);
            }

            var actualItem = ProjectFiles.GetOrAddEntry(documentUri, item);

            if (actualItem != item)
            {
                return(actualItem);
            }

            pyItem.NewAnalysis += OnProjectEntryNewAnalysis;

            if (item is IDocument doc)
            {
                await EnqueueItemAsync(doc);
            }

            foreach (var entryRef in reanalyzeEntries)
            {
                await EnqueueItemAsync(entryRef as IDocument, AnalysisPriority.Low, parse : false);
            }

            return(item);
        }
Exemplo n.º 36
0
 public void UpdateTree(PythonAst ast, IAnalysisCookie fileCookie) {
     throw new NotImplementedException();
 }
Exemplo n.º 37
0
 public StaticPythonParse(PythonAst tree, IAnalysisCookie cookie)
 {
     Tree   = tree;
     Cookie = cookie;
 }
        private void ParseFile(IProjectEntry entry, string filename, TextReader reader, IAnalysisCookie cookie) {
            IJsProjectEntry jsEntry;
            IExternalProjectEntry externalEntry;

            if ((jsEntry = entry as IJsProjectEntry) != null) {
                JsAst ast;
                CollectingErrorSink errorSink;
                ParseNodejsCode(reader, out ast, out errorSink);

                if (ast != null) {
                    jsEntry.UpdateTree(ast, cookie);
                } else {
                    // notify that we failed to update the existing analysis
                    jsEntry.UpdateTree(null, null);
                }
                ProjectItem item;
                if (!_projectFiles.TryGetValue(filename, out item) || item.ReportErrors) {
                    // update squiggles for the buffer. snapshot may be null if we
                    // are analyzing a file that is not open
                    UpdateErrorsAndWarnings(entry, GetSnapshot(reader), errorSink);
                } else {
                    TaskProvider.Clear(entry, ParserTaskMoniker);
                }

                // enqueue analysis of the file
                if (ast != null && ShouldEnqueue()) {
                    _analysisQueue.Enqueue(jsEntry, AnalysisPriority.Normal);
                }
            } else if ((externalEntry = entry as IExternalProjectEntry) != null) {
                externalEntry.ParseContent(reader ?? reader, cookie);
                if (ShouldEnqueue()) {
                    _analysisQueue.Enqueue(entry, AnalysisPriority.Normal);
                }
            }
        }
Exemplo n.º 39
0
 internal ProjectEntry(SourceUnit sourceUnit, string filePath, IAnalysisCookie cookie)
 {
     _sourceUnit = sourceUnit;
     _filePath = filePath;
     _cookie = cookie;
 }
Exemplo n.º 40
0
 public void ParseContent(TextReader content, IAnalysisCookie fileCookie)
 {
     _content = content.ReadToEnd();
 }
Exemplo n.º 41
0
        private async Task <IProjectEntry> AddFileAsync(Uri documentUri, Uri fromSearchPath, IAnalysisCookie cookie = null)
        {
            var item = _projectFiles.GetEntry(documentUri, throwIfMissing: false);

            if (item != null)
            {
                return(item);
            }

            IEnumerable <string> aliases = null;
            var path = GetLocalPath(documentUri);

            if (fromSearchPath != null)
            {
                if (ModulePath.FromBasePathAndFile_NoThrow(GetLocalPath(fromSearchPath), path, out var mp))
                {
                    aliases = new[] { mp.ModuleName };
                }
            }
            else
            {
                aliases = GetImportNames(documentUri).Select(mp => mp.ModuleName).ToArray();
            }

            if (!(aliases?.Any() ?? false))
            {
                aliases = new[] { Path.GetFileNameWithoutExtension(path) };
            }

            var reanalyzeEntries = aliases.SelectMany(a => _analyzer.GetEntriesThatImportModule(a, true)).ToArray();
            var first            = aliases.FirstOrDefault();

            var pyItem = _analyzer.AddModule(first, path, documentUri, cookie);

            item = pyItem;
            foreach (var a in aliases.Skip(1))
            {
                _analyzer.AddModuleAlias(first, a);
            }

            var actualItem = _projectFiles.GetOrAddEntry(documentUri, item);

            if (actualItem != item)
            {
                return(actualItem);
            }

            if (_clientCaps?.python?.analysisUpdates ?? false)
            {
                pyItem.OnNewAnalysis += ProjectEntry_OnNewAnalysis;
            }

            if (item is IDocument doc)
            {
                EnqueueItem(doc);
            }

            if (reanalyzeEntries != null)
            {
                foreach (var entryRef in reanalyzeEntries)
                {
                    _queue.Enqueue(entryRef, AnalysisPriority.Low);
                }
            }

            return(item);
        }
Exemplo n.º 42
0
 public void UpdateTree(SourceUnitTree newAst, IAnalysisCookie newCookie)
 {
     lock (this) {
         _node = newAst;
         _curCookie = newCookie;
     }
     var newParse = OnNewParseTree;
     if (newParse != null) {
         newParse(this, EventArgs.Empty);
     }
 }
Exemplo n.º 43
0
 public void ParseContent(TextReader content, IAnalysisCookie fileCookie) {
     _content = content.ReadToEnd();
     _cookie = fileCookie;
 }
Exemplo n.º 44
0
 public void GetTreeAndCookie(out SourceUnitTree tree, out IAnalysisCookie cookie)
 {
     lock (this) {
         tree = _node;
         cookie = _curCookie;
     }
 }
        private IProjectEntry GetOrCreateProjectEntry(ITextBuffer buffer, IAnalysisCookie analysisCookie) {
            var replEval = buffer.GetReplEvaluator();
            if (replEval != null) {
                // We have a repl window, create an untracked module.
                return _jsAnalyzer.AddModule(
                    Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "repl" + Guid.NewGuid() + ".js"),
                    analysisCookie
                );
            }

            string path = buffer.GetFilePath();
            if (path == null) {
                return null;
            }

            ProjectItem file;
            ProjectEntry entry;
            if (!_projectFiles.TryGetValue(path, out file)) {
                if (buffer.ContentType.IsOfType(NodejsConstants.Nodejs)) {
                    entry = _jsAnalyzer.AddModule(
                        buffer.GetFilePath(),
                        analysisCookie
                    );
                } else {
                    return null;
                }

                _projectFiles[path] = file = new ProjectItem(entry);
            }

            if (_implicitProject && _analysisLevel != AnalysisLevel.NodeLsNone) {
                QueueDirectoryAnalysis(path, file);
            }

            return file.Entry;
        }
Exemplo n.º 46
0
 public void GetTreeAndCookie(out PythonAst ast, out IAnalysisCookie cookie) {
     throw new NotImplementedException();
 }
Exemplo n.º 47
0
 internal ModuleAnalysis(AnalysisUnit unit, InterpreterScope scope, IAnalysisCookie cookie) {
     _unit = unit;
     _scope = scope;
     _cookie = cookie;
 }
Exemplo n.º 48
0
        public void Analyze(CancellationToken cancel)
        {
            if (cancel.IsCancellationRequested) {
                return;
            }

            lock (this) {
                if (_analysis == null) {
                    _analysis = new XamlAnalysis(_filename);
                    _cookie = new FileCookie(_filename);
                }
                _analysis = new XamlAnalysis(_content);

                _version++;

                // update any .py files which depend upon us.
                foreach (var dep in _dependencies) {
                    dep.Analyze(cancel);
                }
            }
        }
Exemplo n.º 49
0
 public void UpdateContent(TextReader content, IAnalysisCookie fileCookie)
 {
     _content = content;
     _cookie  = fileCookie;
 }
Exemplo n.º 50
0
        private IProjectEntry CreateProjectEntry(ITextBuffer buffer, IAnalysisCookie analysisCookie) {
            if (_pyAnalyzer == null) {
                // We aren't able to analyze code, so don't create an entry.
                return null;
            }

            var replEval = buffer.GetReplEvaluator();
            if (replEval != null) {
                // We have a repl window, create an untracked module.
                return _pyAnalyzer.AddModule(null, null, analysisCookie);
            }

            string path = buffer.GetFilePath();
            if (path == null) {
                return null;
            }

            IProjectEntry entry;
            if (!_projectFiles.TryGetValue(path, out entry)) {
                if (buffer.ContentType.IsOfType(PythonCoreConstants.ContentType)) {
                    string modName;
                    try {
                        modName = ModulePath.FromFullPath(path).ModuleName;
                    } catch (ArgumentException) {
                        modName = null;
                    }

                    IPythonProjectEntry[] reanalyzeEntries = null;
                    if (!string.IsNullOrEmpty(modName)) {
                        reanalyzeEntries = Project.GetEntriesThatImportModule(modName, true).ToArray();
                    }

                    entry = _pyAnalyzer.AddModule(
                        modName,
                        buffer.GetFilePath(),
                        analysisCookie
                    );

                    if (reanalyzeEntries != null) {
                        foreach (var entryRef in reanalyzeEntries) {
                            _analysisQueue.Enqueue(entryRef, AnalysisPriority.Low);
                        }
                    }
                } else if (buffer.ContentType.IsOfType("XAML")) {
                    entry = _pyAnalyzer.AddXamlFile(buffer.GetFilePath());
                } else {
                    return null;
                }

                _projectFiles[path] = entry;

                if (ImplicitProject && ShouldAnalyzePath(path)) { // don't analyze std lib
                    QueueDirectoryAnalysis(path);
                }
            }

            return entry;
        }
Exemplo n.º 51
0
 internal ModuleAnalysis(AnalysisUnit unit, InterpreterScope scope, IAnalysisCookie cookie)
 {
     _unit   = unit;
     _scope  = scope;
     _cookie = cookie;
 }