Пример #1
0
        public static bool TryGetSemanticModel(this ITextSnapshot snapshot, CancellationToken cancellationToken, out SemanticModel semanticModel)
        {
            if (HlslPackage.Instance != null && !HlslPackage.Instance.Options.AdvancedOptions.EnableIntelliSense)
            {
                semanticModel = null;
                return false;
            }

            try
            {
                semanticModel = CachedSemanticModels.GetValue(snapshot, key =>
                {
                    try
                    {
                        var syntaxTree = key.GetSyntaxTree(cancellationToken);
                        var compilation = new Compilation(syntaxTree);
                        return compilation.GetSemanticModel(cancellationToken);
                    }
                    catch (OperationCanceledException)
                    {
                        throw;
                    }
                    catch (Exception ex)
                    {
                        Logger.Log($"Failed to create semantic model: {ex}");
                        return null;
                    }
                });
            }
            catch (OperationCanceledException)
            {
                semanticModel = null;
            }

            return semanticModel != null;
        }
Пример #2
0
 internal SemanticModel(Compilation compilation, BindingResult bindingResult)
 {
     Compilation = compilation;
     _bindingResult = bindingResult;
 }