coc-pyright 1.1.228 → 1.1.232

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -1,6 +1,8 @@
1
1
  var __create = Object.create;
2
2
  var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
7
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
8
  var __getProtoOf = Object.getPrototypeOf;
@@ -18,6 +20,7 @@ var __spreadValues = (a, b) => {
18
20
  }
19
21
  return a;
20
22
  };
23
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
24
  var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
22
25
  var __commonJS = (cb, mod) => function __require() {
23
26
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
@@ -5060,8 +5063,8 @@ var require_lib = __commonJS({
5060
5063
  var require_untildify = __commonJS({
5061
5064
  "node_modules/untildify/index.js"(exports, module2) {
5062
5065
  "use strict";
5063
- var os = require("os");
5064
- var homeDirectory = os.homedir();
5066
+ var os2 = require("os");
5067
+ var homeDirectory = os2.homedir();
5065
5068
  module2.exports = (pathWithTilde) => {
5066
5069
  if (typeof pathWithTilde !== "string") {
5067
5070
  throw new TypeError(`Expected a string, got ${typeof pathWithTilde}`);
@@ -15030,7 +15033,7 @@ var require_interval = __commonJS({
15030
15033
  exports.interval = void 0;
15031
15034
  var async_1 = require_async();
15032
15035
  var timer_1 = require_timer();
15033
- function interval(period, scheduler) {
15036
+ function interval2(period, scheduler) {
15034
15037
  if (period === void 0) {
15035
15038
  period = 0;
15036
15039
  }
@@ -15042,7 +15045,7 @@ var require_interval = __commonJS({
15042
15045
  }
15043
15046
  return timer_1.timer(period, period, scheduler);
15044
15047
  }
15045
- exports.interval = interval;
15048
+ exports.interval = interval2;
15046
15049
  }
15047
15050
  });
15048
15051
 
@@ -18541,17 +18544,17 @@ var require_timeInterval = __commonJS({
18541
18544
  var last = scheduler.now();
18542
18545
  source.subscribe(OperatorSubscriber_1.createOperatorSubscriber(subscriber, function(value) {
18543
18546
  var now = scheduler.now();
18544
- var interval = now - last;
18547
+ var interval2 = now - last;
18545
18548
  last = now;
18546
- subscriber.next(new TimeInterval(value, interval));
18549
+ subscriber.next(new TimeInterval(value, interval2));
18547
18550
  }));
18548
18551
  });
18549
18552
  }
18550
18553
  exports.timeInterval = timeInterval;
18551
18554
  var TimeInterval = function() {
18552
- function TimeInterval2(value, interval) {
18555
+ function TimeInterval2(value, interval2) {
18553
18556
  this.value = value;
18554
- this.interval = interval;
18557
+ this.interval = interval2;
18555
18558
  }
18556
18559
  return TimeInterval2;
18557
18560
  }();
@@ -21223,6 +21226,12 @@ var _PythonSettings = class {
21223
21226
  return process.platform === "win32" ? import_path.default.join(p, "Scripts", "python.exe") : import_path.default.join(p, "bin", "python");
21224
21227
  }
21225
21228
  try {
21229
+ if (process.env.VIRTUAL_ENV && import_fs_extra.default.existsSync(import_path.default.join(process.env.VIRTUAL_ENV, "pyvenv.cfg"))) {
21230
+ return pythonBinFromPath(process.env.VIRTUAL_ENV);
21231
+ }
21232
+ if (process.env.CONDA_PREFIX) {
21233
+ return pythonBinFromPath(process.env.CONDA_PREFIX);
21234
+ }
21226
21235
  let p = import_path.default.join(this.workspaceRoot, ".python-version");
21227
21236
  if (import_fs_extra.default.existsSync(p)) {
21228
21237
  if (!process.env.PYENV_VERSION) {
@@ -21249,12 +21258,6 @@ var _PythonSettings = class {
21249
21258
  return pythonBinFromPath(info);
21250
21259
  }
21251
21260
  }
21252
- if (process.env.VIRTUAL_ENV && import_fs_extra.default.existsSync(import_path.default.join(process.env.VIRTUAL_ENV, "pyvenv.cfg"))) {
21253
- return pythonBinFromPath(process.env.VIRTUAL_ENV);
21254
- }
21255
- if (process.env.CONDA_PREFIX) {
21256
- return pythonBinFromPath(process.env.CONDA_PREFIX);
21257
- }
21258
21261
  const files = import_fs_extra.default.readdirSync(this.workspaceRoot);
21259
21262
  for (const file of files) {
21260
21263
  const x = import_path.default.join(this.workspaceRoot, file);
@@ -22012,32 +22015,152 @@ var DarkerFormatter = class extends BaseFormatter {
22012
22015
  };
22013
22016
 
22014
22017
  // src/formatters/blackd.ts
22015
- var import_coc7 = require("coc.nvim");
22016
22018
  var import_child_process2 = require("child_process");
22019
+ var import_coc7 = require("coc.nvim");
22020
+
22021
+ // node_modules/get-port/index.js
22022
+ var import_node_net = __toESM(require("net"), 1);
22023
+ var import_node_os = __toESM(require("os"), 1);
22024
+ var Locked = class extends Error {
22025
+ constructor(port) {
22026
+ super(`${port} is locked`);
22027
+ }
22028
+ };
22029
+ var lockedPorts = {
22030
+ old: /* @__PURE__ */ new Set(),
22031
+ young: /* @__PURE__ */ new Set()
22032
+ };
22033
+ var releaseOldLockedPortsIntervalMs = 1e3 * 15;
22034
+ var interval;
22035
+ var getLocalHosts = () => {
22036
+ const interfaces = import_node_os.default.networkInterfaces();
22037
+ const results = /* @__PURE__ */ new Set([void 0, "0.0.0.0"]);
22038
+ for (const _interface of Object.values(interfaces)) {
22039
+ for (const config of _interface) {
22040
+ results.add(config.address);
22041
+ }
22042
+ }
22043
+ return results;
22044
+ };
22045
+ var checkAvailablePort = (options) => new Promise((resolve, reject) => {
22046
+ const server = import_node_net.default.createServer();
22047
+ server.unref();
22048
+ server.on("error", reject);
22049
+ server.listen(options, () => {
22050
+ const { port } = server.address();
22051
+ server.close(() => {
22052
+ resolve(port);
22053
+ });
22054
+ });
22055
+ });
22056
+ var getAvailablePort = async (options, hosts) => {
22057
+ if (options.host || options.port === 0) {
22058
+ return checkAvailablePort(options);
22059
+ }
22060
+ for (const host of hosts) {
22061
+ try {
22062
+ await checkAvailablePort({ port: options.port, host });
22063
+ } catch (error) {
22064
+ if (!["EADDRNOTAVAIL", "EINVAL"].includes(error.code)) {
22065
+ throw error;
22066
+ }
22067
+ }
22068
+ }
22069
+ return options.port;
22070
+ };
22071
+ var portCheckSequence = function* (ports) {
22072
+ if (ports) {
22073
+ yield* ports;
22074
+ }
22075
+ yield 0;
22076
+ };
22077
+ async function getPorts(options) {
22078
+ let ports;
22079
+ let exclude = /* @__PURE__ */ new Set();
22080
+ if (options) {
22081
+ if (options.port) {
22082
+ ports = typeof options.port === "number" ? [options.port] : options.port;
22083
+ }
22084
+ if (options.exclude) {
22085
+ const excludeIterable = options.exclude;
22086
+ if (typeof excludeIterable[Symbol.iterator] !== "function") {
22087
+ throw new TypeError("The `exclude` option must be an iterable.");
22088
+ }
22089
+ for (const element of excludeIterable) {
22090
+ if (typeof element !== "number") {
22091
+ throw new TypeError("Each item in the `exclude` option must be a number corresponding to the port you want excluded.");
22092
+ }
22093
+ if (!Number.isSafeInteger(element)) {
22094
+ throw new TypeError(`Number ${element} in the exclude option is not a safe integer and can't be used`);
22095
+ }
22096
+ }
22097
+ exclude = new Set(excludeIterable);
22098
+ }
22099
+ }
22100
+ if (interval === void 0) {
22101
+ interval = setInterval(() => {
22102
+ lockedPorts.old = lockedPorts.young;
22103
+ lockedPorts.young = /* @__PURE__ */ new Set();
22104
+ }, releaseOldLockedPortsIntervalMs);
22105
+ if (interval.unref) {
22106
+ interval.unref();
22107
+ }
22108
+ }
22109
+ const hosts = getLocalHosts();
22110
+ for (const port of portCheckSequence(ports)) {
22111
+ try {
22112
+ if (exclude.has(port)) {
22113
+ continue;
22114
+ }
22115
+ let availablePort = await getAvailablePort(__spreadProps(__spreadValues({}, options), { port }), hosts);
22116
+ while (lockedPorts.old.has(availablePort) || lockedPorts.young.has(availablePort)) {
22117
+ if (port !== 0) {
22118
+ throw new Locked(port);
22119
+ }
22120
+ availablePort = await getAvailablePort(__spreadProps(__spreadValues({}, options), { port }), hosts);
22121
+ }
22122
+ lockedPorts.young.add(availablePort);
22123
+ return availablePort;
22124
+ } catch (error) {
22125
+ if (!["EADDRINUSE", "EACCES"].includes(error.code) && !(error instanceof Locked)) {
22126
+ throw error;
22127
+ }
22128
+ }
22129
+ }
22130
+ throw new Error("No available ports found");
22131
+ }
22132
+
22133
+ // src/formatters/blackd.ts
22017
22134
  var BlackdFormatter = class extends BaseFormatter {
22018
22135
  constructor(pythonSettings, outputChannel) {
22019
22136
  super("blackd", pythonSettings, outputChannel);
22020
22137
  this.pythonSettings = pythonSettings;
22021
22138
  this.outputChannel = outputChannel;
22022
- this.blackdServer = null;
22023
22139
  this.blackdHTTPURL = "";
22024
22140
  this.blackdHTTPURL = this.pythonSettings.formatting.blackdHTTPURL;
22025
22141
  if (!this.blackdHTTPURL.length) {
22026
- const blackdPath = this.pythonSettings.formatting.blackdPath;
22027
- this.blackdServer = (0, import_child_process2.spawn)(blackdPath).on("error", (e) => {
22028
- this.outputChannel.appendLine("");
22029
- this.outputChannel.appendLine("spawn blackd HTTP server error");
22030
- this.outputChannel.appendLine(e.message);
22031
- this.outputChannel.appendLine('make sure you have installed blackd by `pip install "black[d]"`');
22032
- this.blackdServer = null;
22033
- });
22142
+ this.lauchServer();
22034
22143
  }
22035
22144
  }
22145
+ async lauchServer() {
22146
+ const port = await getPorts({ port: 45484 });
22147
+ this.blackdHTTPURL = `http://127.0.0.1:${port}`;
22148
+ const blackdPath = this.pythonSettings.formatting.blackdPath;
22149
+ (0, import_child_process2.spawn)(blackdPath, ["--bind-port", String(port)]).on("error", (e) => {
22150
+ this.outputChannel.appendLine("");
22151
+ this.outputChannel.appendLine("spawn blackd HTTP server error");
22152
+ this.outputChannel.appendLine(e.message);
22153
+ this.outputChannel.appendLine('make sure you have installed blackd by `pip install "black[d]"`');
22154
+ this.blackdHTTPURL = "";
22155
+ });
22156
+ }
22036
22157
  async handle(document) {
22158
+ if (!this.blackdHTTPURL.length) {
22159
+ return Promise.resolve([]);
22160
+ }
22037
22161
  try {
22038
- const _url = this.blackdHTTPURL || "http://127.0.0.1:45484";
22039
22162
  const headers = Object.assign({ "X-Diff": 1 }, this.pythonSettings.formatting.blackdHTTPHeaders);
22040
- const patch = await (0, import_coc7.fetch)(_url, { method: "POST", data: document.getText(), headers });
22163
+ const patch = await (0, import_coc7.fetch)(this.blackdHTTPURL, { method: "POST", data: document.getText(), headers });
22041
22164
  this.outputChannel.appendLine("");
22042
22165
  this.outputChannel.appendLine(`${"#".repeat(10)} ${this.Id} output:`);
22043
22166
  this.outputChannel.appendLine(patch.toString());
@@ -22055,15 +22178,11 @@ var BlackdFormatter = class extends BaseFormatter {
22055
22178
  }
22056
22179
  }
22057
22180
  formatDocument(document, _options, _token, range) {
22058
- const errorMessage = async (msg) => {
22181
+ if (range) {
22182
+ const msg = "blackd does not support range formatting";
22059
22183
  this.outputChannel.appendLine(msg);
22060
22184
  import_coc7.window.showErrorMessage(msg);
22061
- return [];
22062
- };
22063
- if (range)
22064
- return errorMessage('Black does not support the "Format Selection" command');
22065
- if (!this.blackdServer && !this.blackdHTTPURL) {
22066
- return errorMessage("blackd server error");
22185
+ return Promise.resolve([]);
22067
22186
  }
22068
22187
  return this.handle(document);
22069
22188
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coc-pyright",
3
- "version": "1.1.228",
3
+ "version": "1.1.232",
4
4
  "description": "Pyright extension for coc.nvim, static type checker for Python",
5
5
  "author": "Heyward Fann <fannheyward@gmail.com>",
6
6
  "license": "MIT",
@@ -49,6 +49,7 @@
49
49
  "esbuild": "^0.14.2",
50
50
  "eslint": "^8.4.1",
51
51
  "fs-extra": "^10.0.0",
52
+ "get-port": "^6.1.2",
52
53
  "iconv-lite": "^0.6.2",
53
54
  "md5": "^2.3.0",
54
55
  "named-js-regexp": "^1.3.5",
@@ -776,6 +777,17 @@
776
777
  "error"
777
778
  ]
778
779
  },
780
+ "reportUnusedExpression": {
781
+ "type": "string",
782
+ "description": "Diagnostics for simple expressions whose value is not used in any way.",
783
+ "default": "warning",
784
+ "enum": [
785
+ "none",
786
+ "information",
787
+ "warning",
788
+ "error"
789
+ ]
790
+ },
779
791
  "reportUnnecessaryTypeIgnoreComment": {
780
792
  "type": "string",
781
793
  "description": "Diagnostics for '# type: ignore' comments that have no effect.",
@@ -1273,7 +1285,7 @@
1273
1285
  "python.formatting.blackdHTTPHeaders": {
1274
1286
  "type": "object",
1275
1287
  "default": {},
1276
- "description": "Custom headers POST to blackd server, checkout https://github.com/psf/black/blob/master/docs/blackd.md#protocol",
1288
+ "description": "Custom headers POST to blackd server, checkout https://black.readthedocs.io/en/stable/usage_and_configuration/black_as_a_server.html#protocol",
1277
1289
  "scope": "resource"
1278
1290
  },
1279
1291
  "python.formatting.provider": {
@@ -1391,6 +1403,6 @@
1391
1403
  ]
1392
1404
  },
1393
1405
  "dependencies": {
1394
- "pyright": "^1.1.228"
1406
+ "pyright": "^1.1.232"
1395
1407
  }
1396
1408
  }
@@ -467,6 +467,12 @@
467
467
  "title": "Controls reporting of call expressions that returns Coroutine whose results are not consumed",
468
468
  "default": "error"
469
469
  },
470
+ "reportUnusedExpression": {
471
+ "$id": "#/properties/reportUnusedExpression",
472
+ "$ref": "#/definitions/diagnostic",
473
+ "title": "Controls reporting of simple expressions whose value is not used in any way",
474
+ "default": "warning"
475
+ },
470
476
  "reportUnnecessaryTypeIgnoreComment": {
471
477
  "$id": "#/properties/reportUnnecessaryTypeIgnoreComment",
472
478
  "$ref": "#/definitions/diagnostic",