Implement a hover provider in a VS Code extension that logs the word under the cursor when hovered over

I want to implement something like that.
hover example

Now, here’s some of my extension code. I’m trying to select a code snippet, analyze it and then get some feedback on variables when hovering over them.
Here’s the code for that

export function activate(context: vscode.ExtensionContext) {

    // This line of code will only be executed once when the extension is activated
    console.log('Congratulations, your "injectguard" is now active!');

    let disposable = vscode.commands.registerCommand('injectguard.injection', async () => {

        const editor = vscode.window.activeTextEditor;
        if (!editor) {
            vscode.window.showInformationMessage('No editor is active');
            return;
        }

        // Retrieve selected code
        const selection = editor.selection;
        const sourceCode = editor.document.getText(selection);


        // Trivial test
        const isVulnerable = /d/.test(sourceCode);
        
        // highlight in red if there is an injection vulnerability
        const decorationType = vscode.window.createTextEditorDecorationType({
            backgroundColor: 'rgba(255,0,0,0.3)' // Light red background
        });

        if (isVulnerable) {
            // Add decoration to the selected text
            editor.setDecorations(decorationType, [selection]);
            vscode.window.showInformationMessage('Code snippet vulnerable!');
            
        } else {
            // Clear decorations if there are no vulnerabilities
            editor.setDecorations(decorationType, []);
            vscode.window.showInformationMessage('Selected text is fine.');
        }
        
    });

    context.subscriptions.push(disposable);
}

And package.json

{
  "name": "injectguard",
  "displayName": "InjectGuard",
  "description": "analyzes code sample and determines if it's vulnerable to injection attacks ",
  "version": "0.0.1",
  "engines": {
    "vscode": "^1.89.1"
  },
  "categories": [
    "Other"
  ],
  "capabilities": {
    "hoverProvider": "true"
  },
  "activationEvents": [],
  "main": "./out/extension.js",
  "contributes": {
    "commands": [
      {
        "command": "injectguard.injection",
        "title": "InjectGuard : domain analysis "
      }
    ],
    "menus": {
      "editor/context": [
        {
          "command": "injectguard.injection",
          "group": "bookmarks",
          "when": "editorHasSelection"
        }
      ]
    }
  },
  "scripts": {
    "generate-client": "openapi-ts --input http://localhost:8000/openapi.json --output ./src/client --client axios",
    "vscode:prepublish": "npm run compile",
    "compile": "tsc -p ./",
    "watch": "tsc -watch -p ./",
    "pretest": "npm run compile && npm run lint",
    "lint": "eslint src --ext ts",
    "test": "vscode-test"
  },
  "devDependencies": {
    "@hey-api/openapi-ts": "^0.47.2",
    "@types/mocha": "^10.0.6",
    "@types/node": "18.x",
    "@types/vscode": "^1.89.0",
    "@typescript-eslint/eslint-plugin": "^7.11.0",
    "@typescript-eslint/parser": "^7.11.0",
    "@vscode/test-cli": "^0.0.9",
    "@vscode/test-electron": "^2.4.0",
    "eslint": "^8.57.0",
    "typescript": "^5.4.5"
  },
  "dependencies": {
    "axios": "^1.7.2",
    "php-parser": "^3.1.5"
  }
}

I’ve tried reading the docs but I find it lacking in detail.

Below the links I found when looking for docs :

when looking in the show hover section

I know the code I should be adding looks something like this (asked chatGPT for it)

let disposable = vscode.languages.registerHoverProvider('*', {
        provideHover(document, position, token) {

            const editor = vscode.window.activeTextEditor;
            if (!editor) {
                vscode.window.showInformationMessage('No editor is active');
                return;
            }
            // Retrieve selected code
            const selection = editor.selection;

            // Get the word at the hovered position
            const range = document.getWordRangeAtPosition(position);
            const word = document.getText(range);
                        
            // Returning a Hover object with content is optional
            if(position.line >= selection.start.line && position.line <= selection.end.line )
                return new vscode.Hover(`You hovered over the word: ${position.line}`);
        }
    });

When I tried to run to run this code with the package.json also generated by chatGpt it worked pretty.
Note : the package.json generated by ChatGPT has older version dependencies but seems roughly the same as mine.
Now,
The problem is that I’m trying to add this hover feature to the code I already wrote above. I tried writing two different disposables but the hover disposable doesn’t work while the injectguard disposable works without a problem.

In sum, I’m having trouble understanding how all of this disposable philosophy work and I’d appreciate your feedback on that. Additionally, it would be fantastic if both the inject guard and the hover feature could work simultaneously!
Thanks for sharing !

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật