コード例 #1
0
        public async Task <ExtensionCommandResult> ExtensionCommand(ExtensionCommandParams @params, CancellationToken token)
        {
            if (string.IsNullOrEmpty(@params.extensionName))
            {
                throw new ArgumentNullException(nameof(@params.extensionName));
            }

            if (!_extensions.TryGetValue(@params.extensionName, out var ext))
            {
                throw new LanguageServerException(LanguageServerException.UnknownExtension, "No extension loaded with name: " + @params.extensionName);
            }

            return(new ExtensionCommandResult {
                properties = await ext?.ExecuteCommand(@params.command, @params.properties, token)
            });
        }
コード例 #2
0
        public async Task ExtensionCommand()
        {
            var s = await CreateServer();

            var u = await AddModule(s, "x = 1\ny = 2\nz = 'abc'");

            await s.LoadExtensionAsync(new PythonAnalysisExtensionParams {
                assembly   = typeof(GetAllExtensionProvider).Assembly.FullName,
                typeName   = typeof(GetAllExtensionProvider).FullName,
                properties = new Dictionary <string, object> {
                    ["typeid"] = BuiltinTypeId.Int.ToString()
                }
            }, null, CancellationToken.None);

            var cmd = new ExtensionCommandParams {
                extensionName = "getall",
                command       = "Int",
                properties    = new Dictionary <string, object> {
                    ["uri"] = u.AbsoluteUri, ["line"] = 1, ["column"] = 1
                }
            };

            var res = (await s.ExtensionCommand(cmd, CancellationToken.None)).properties?["names"];

            res.Should().BeOfType <List <string> >().Which.Should().OnlyContain("x", "y");

            cmd.command = BuiltinTypeId_Str.ToString();
            res         = (await s.ExtensionCommand(cmd, CancellationToken.None)).properties?["names"];
            res.Should().BeNull();

            await s.LoadExtensionAsync(new PythonAnalysisExtensionParams {
                assembly   = typeof(GetAllExtensionProvider).Assembly.FullName,
                typeName   = typeof(GetAllExtensionProvider).FullName,
                properties = new Dictionary <string, object> {
                    ["typeid"] = BuiltinTypeId_Str.ToString()
                }
            }, null, CancellationToken.None);

            cmd.command = BuiltinTypeId_Str.ToString();
            res         = (await s.ExtensionCommand(cmd, CancellationToken.None)).properties?["names"];
            res.Should().BeOfType <List <string> >().Which.Should().Contain("z", "__name__", "__file__");

            cmd.command = "Int";
            res         = (await s.ExtensionCommand(cmd, CancellationToken.None)).properties?["names"];
            res.Should().BeNull();
        }
コード例 #3
0
        public async Task ExtensionCommand()
        {
            var s = await CreateServer();

            var u = await AddModule(s, "x = 1\ny = 2\nz = 'abc'");

            await s.LoadExtension(new PythonAnalysisExtensionParams {
                assembly   = typeof(GetAllExtensionProvider).Assembly.FullName,
                typeName   = typeof(GetAllExtensionProvider).FullName,
                properties = new Dictionary <string, object> {
                    ["typeid"] = BuiltinTypeId.Int.ToString()
                }
            });

            List <string> res;
            var           cmd = new ExtensionCommandParams {
                extensionName = "getall",
                command       = "Int",
                properties    = new Dictionary <string, object> {
                    ["uri"] = u.AbsoluteUri, ["line"] = 1, ["column"] = 1
                }
            };

            res = (await s.ExtensionCommand(cmd)).properties?["names"] as List <string>;
            Assert.IsNotNull(res);
            AssertUtil.ContainsExactly(res, "x", "y");
            cmd.command = BuiltinTypeId_Str.ToString();
            res         = (await s.ExtensionCommand(cmd)).properties?["names"] as List <string>;
            Assert.IsNull(res);

            await s.LoadExtension(new PythonAnalysisExtensionParams {
                assembly   = typeof(GetAllExtensionProvider).Assembly.FullName,
                typeName   = typeof(GetAllExtensionProvider).FullName,
                properties = new Dictionary <string, object> {
                    ["typeid"] = BuiltinTypeId_Str.ToString()
                }
            });

            cmd.command = BuiltinTypeId_Str.ToString();
            res         = (await s.ExtensionCommand(cmd)).properties?["names"] as List <string>;
            Assert.IsNotNull(res);
            AssertUtil.ContainsAtLeast(res, "z", "__name__", "__file__");
            cmd.command = "Int";
            res         = (await s.ExtensionCommand(cmd)).properties?["names"] as List <string>;
            Assert.IsNull(res);
        }