Giter Site home page Giter Site logo

Comments (1)

benknoble avatar benknoble commented on June 21, 2024

Here's a patch that fixed this for me. I'm not a typescript developer, so I actually modified the built JS until it worked, then tried to translate back:

diff --git i/src/languageserver/handlers/settingsHandlers.ts w/src/languageserver/handlers/settingsHandlers.ts
index 95ddba7..2fd4e73 100644
--- i/src/languageserver/handlers/settingsHandlers.ts
+++ w/src/languageserver/handlers/settingsHandlers.ts
@@ -14,6 +14,7 @@ import { Telemetry } from '../../languageservice/telemetry';
 import { ValidationHandler } from './validationHandlers';
 
 export class SettingsHandler {
+  private readonly globalSettings: Settings?; // or Settings and initialize to defaults?
   constructor(
     private readonly connection: Connection,
     private readonly languageService: LanguageService,
@@ -31,13 +32,26 @@ export class SettingsHandler {
         this.telemetry.sendError('yaml.settings.error', { error: convertErrorToTelemetryMsg(err) });
       }
     }
-    this.connection.onDidChangeConfiguration(() => this.pullConfiguration());
+    this.connection.onDidChangeConfiguration((event) => {
+      // probably missing some type annotations to make this work
+      if (event && Object.prototype.hasOwnProperty.call(event, 'settings')) {
+        this.globalSettings = event.settings;
+      }
+      this.pullConfiguration()
+    });
   }
 
   /**
    *  The server pull the 'yaml', 'http.proxy', 'http.proxyStrictSSL', '[yaml]' settings sections
    */
   async pullConfiguration(): Promise<void> {
+    // might need a null check on this.globalSettings here; in the JS version I
+    // set globalSettings to {} in the constructor, but that might not pass the
+    // typechecker as a "Settigns" object
+    if (!this.yamlSettings.hasConfigurationCapability) {
+      await this.setConfiguration(this.globalSettings);
+      return;
+    }
     const config = await this.connection.workspace.getConfiguration([
       { section: 'yaml' },
       { section: 'http' },

For reference, here's the modified Javascript that definitely works:

class SettingsHandler {
    constructor(connection, languageService, yamlSettings, validationHandler, telemetry) {
        this.connection = connection;
        this.languageService = languageService;
        this.yamlSettings = yamlSettings;
        this.validationHandler = validationHandler;
        this.telemetry = telemetry;
        this.globalSettings = {};
    }
    async registerHandlers() {
        if (this.yamlSettings.hasConfigurationCapability && this.yamlSettings.clientDynamicRegisterSupport) {
            try {
                // Register for all configuration changes.
                await this.connection.client.register(vscode_languageserver_1.DidChangeConfigurationNotification.type);
            }
            catch (err) {
                this.telemetry.sendError('yaml.settings.error', { error: (0, objects_1.convertErrorToTelemetryMsg)(err) });
            }
        }
        this.connection.onDidChangeConfiguration((event) => {
          if (event && Object.prototype.hasOwnProperty.call(event, 'settings')) {
            this.globalSettings = event.settings;
          }
          this.pullConfiguration()
        });
    }
    /**
     *  The server pull the 'yaml', 'http.proxy', 'http.proxyStrictSSL', '[yaml]' settings sections
     */
    async pullConfiguration() {
      if (!this.yamlSettings.hasConfigurationCapability) {
        await this.setConfiguration(this.globalSettings);
        return;
      }
// snip: omitted

from yaml-language-server.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.