After saving the document, the newly added autocomplete items do not appear in the autocomplete list

This particular sample appears to function correctly until it is saved. While using "Untitled-1" everything works as expected, but once saved as "test.py", the item does not get added to the autocomplete list. Despite running "npm install" in the directory multiple times, the issue persists. The file extensions that do not work are:

  • .ts
  • .c
  • .cpp
  • .js
  • .py
  • .sh

However, these extensions do work:

  • No extension (unsaved)
  • .txt

The problem was also reproduced on a Windows machine. To replicate the issue, follow these steps:

  1. Clone the Git repository
  2. Run "npm install" in the completions-sample folder
  3. Open the completions-sample folder in vscode
  4. Select "Start Debugging" under "Debug" to run the extension
  5. Create a new file without saving
  6. Press ctrl+shift+p and choose "Trigger Suggest". A menu should appear with items from the extension code like "Hello World!"
  7. Add an extension to the file by saving it, such as ".py". Repeat step 5, and notice that the menu no longer includes custom autocomplete items.

This was tested on:

  • Ubuntu 18.04.2 LTS
  • vscode 1.41.0

Answer №1

When I reached out for assistance on the official vscode repository, I learned that in order to make autocomplete items appear, it is necessary to modify the language identifier. By default, it is "plaintext," which restricts the appearance of autocomplete items to plaintext documents only.

let provider = vscode.languages.registerCompletionItemProvider('plaintext', {

    provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken, context: vscode.CompletionContext) {

        // A basic completion item that inserts 'Hello World!'
        const simpleCompletion = new vscode.CompletionItem('Hello World!');

        // Returns all completion items as an array
        return [
            simpleCompletion
        ];
    }
});

If I wish for the items to be visible in Python documents, I can identify its language ID on this page and update the code like so:

let provider = vscode.languages.registerCompletionItemProvider('python', {

    provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken, context: vscode.CompletionContext) {

        // A basic completion item that inserts 'Hello World!'
        const simpleCompletion = new vscode.CompletionItem('Hello World!');

        // Returns all completion items as an array
        return [
            simpleCompletion
        ];
    }
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Transforming a JavaScript chained setter into TypeScript

I have been utilizing this idiom in JavaScript to facilitate the creation of chained setters. function bar() { let p = 0; function f() { } f.prop = function(d) { return !arguments.length ? p : (p = d, f); } return f; } ...

Step-by-step guide for inputting a sophisticated formula in exceljs using JavaScript

Currently, I am working on a project that involves exporting data into multiple xlsx sheets. One of the sheets requires me to add a formula in cells that meet certain conditions before adding data from the first sheet. Here is an example: Ref !== null ? wo ...

The TypeScript error reads: "An element is implicitly assigned the 'any' type because an expression of type 'any' cannot be used to index a specific type."

[Hey there!][1] Encountering this TypeScript error message: { "Element implicitly has an 'any' type because expression of type 'any' can't be used to index type '{ 0: { image: string; title: string; text: string; }; 1: { ...

Incorporating docsify CSS styling into Markdown within the VScode environment

When it comes to building my blog, I've decided to go with docsify and manage my markdown files using VScode. I wanted a preview of my blog, and after noticing that <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/docsify@4/lib/t ...

Is there a way to modify an image that has been dynamically inserted in an Angular application?

I'm facing an issue with dynamically added input files in Angular. Whenever I upload a file, it changes all the images of the input files instead of just the one I want to target. How can I resolve this problem? Please help. images = [ {url: &ap ...

Error: Trying to define multiple classes in the same file results in a ReferenceError for undefined Object

My current setup involves using node.js version 7.44. Within the file user.models.ts, I've defined multiple classes like so: import { Exclude, Expose } from "class-transformer"; export class User { @Expose() _id: string; @Expose() fname: st ...

Utilizing NgRx 8 Actions in Conjunction with NgRx 7 Reducers: An Implementation

In the development of my new Angular 8 project, I have incorporated the NgRx library. It was mentioned to me that actions are created using createAction in NgRx 8, but reducers are built using NgRx 7. Initially, I implemented my reducer with NgRx 8, but no ...

Validation of ngModel in Angular for a subcomponent form

One of the components I'm working on has a model structured like this: model={ name, surname, age, birthDate } I am passing this model to a sub-component. <form #form="ngForm" > <input name="name" [(ngModel)]="model.name" required> < ...

Converting Typescript fat arrow syntax to regular Javascript syntax

I recently started learning typescript and I'm having trouble understanding the => arrow function. Could someone clarify the meaning of this JavaScript code snippet for me: this.dropDownFilter = values => values.filter(option => option.value ...

When executing the project, the information fails to appear on the screen

I am new to angular and I have been trying to use the http module to fetch data from my backend. In my user.component.html file, I have the following code: <tr *ngFor="let item of transporter.liste"> <td>{{item.name}}</td> ...

Some elements that fit the criteria of 'number | function' are not callable at all

Consider a basic function like this: export const sum = (num?: number) => { const adder = (n: number) => { if (!n) { return num; } num = (num && num + n) || n; return adder; }; return a ...

Using Typescript to specify the type of data returned from a POST request

In my code, I am making a post request using got in the following way: const got = got_.extend({ prefixUrl: serviceUrl, responseType: 'json' }) const { body } = await got.post('newAddress', { json: { userId } }) The conten ...

The identifier 'id' is not recognized within the 'never' type in Angular

Hello there, I am currently working on a small project for a store website. You can find the project here. However, I have encountered an issue when trying to move items to the cart. Specifically, in the source code file app/components/product-list/produc ...

How to call a function within a component from another component without encountering the "Cannot read property" error

Having trouble calling a function from one component in another by passing the reference of one to the other. I keep getting a "Cannot read property" error. Below is the code snippet Alert Component import { Component, OnInit, Output } from '@angula ...

What is the reason behind the Partial input basic type returning itself?

Snippet of code excerpt: type PartialType<T> = { [P in keyof T]?: T[P]; } I am curious about why the PartialType input basic type (such as string returning string) returns itself instead of throwing an error or an object. // undef => undefined t ...

Sending properties via react router link in TypeScript

I have successfully defined my routes and made my links functional. I am now trying to figure out how to pass a prop through the link when the component is called by the router. It seems like a challenging task. To understand better, take a look at this c ...

How can I use Typescript to define a function that accepts a particular string as an argument and returns another specific string?

I've been working on this code snippet: const Locales = { en_gb: 'en-gb', en_us: 'en-us', } as const type ApiLocales = typeof Locales[keyof typeof Locales] type DatabaseLocales = keyof typeof Locales function databaseLanguage ...

Extracting Table(Array) Index into a Component in Angular

For my data on the HTML page, I created a 2-dimensional array. <tbody> <tr *ngFor="let i of myarray2"> <td *ngFor="let j of i"> {{j}} </td> </tr> </tbody> This is how it appears: https://i.sstatic.ne ...

Step-by-Step Tutorial: Displaying Loading Text in Child Components with Angular 4

Within my "event.component" file, I have a nested component (app-grouplist) <div class="group-list"> <app-grouplist [hasStarted]="started" [hasEnded]="ended" Displaying Loading Groups... </app-grouplist> </div> Upon the initial page ...

Using dictionary keys as valid property values

I have put together a dictionary like so: const iconTypesDictionary: { [key: string]: IconPrefix } = { solid: 'fas', regular: 'far', light: 'fal', } My goal is to be able to utilize the keys of this dictionary as potent ...