Skip to content

Segmentation fault using copilot sources when accepting specific completion #1777

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
2 tasks done
TzeroOcne opened this issue May 16, 2025 · 2 comments
Open
2 tasks done
Labels
bug Something isn't working

Comments

@TzeroOcne
Copy link

Make sure you have done the following

  • Updated to the latest version of blink.cmp
  • Searched for existing issues and documentation (try <C-k> on https://cmp.saghen.dev)

Bug Description

I'm trying to use copilot with blink using blink-cmp-copilot and copilot.lua but I got segmentation fault when accepting specific completion
the file I use that consistently result segmentation fault is this one

import { Initializer, Inject, Service } from 'fastify-decorators';
import { Brackets, FindOptionsWhere, Repository } from 'typeorm';
import { PostgreSQLConnection } from '../../../data/connection/postgresql.connection';
import { BaseSQLDAO } from '../../common/common.repository';
import { EntityCategory } from '../../../data/entities/pgsql/EntityCategory.entity';
import { RequestUser } from '../../libs/types';
import { ERR_BAD_REQUEST, ERR_INTERNAL_SERVER } from '../../libs/constants/errors';
import { uuidRegex } from '../../libs/constants/regexp';
import {
  // prettier-ignore
  EntityCategoryMapping,
} from '../../../data/entities/pgsql/mapping/EntityCategoryMapping.entity';
import { EntityCategoryPaginationParamsDTO } from './entityCategory.dto';
import { clamp } from '../../libs/utils/helpers';

@Service()
export class EntityCategoryRepository extends BaseSQLDAO<EntityCategory> {
  @Inject(PostgreSQLConnection)
  protected psql: PostgreSQLConnection;

  protected repository: Repository<EntityCategory>;

  protected categoryMapRepository: Repository<EntityCategoryMapping>;

  @Initializer([PostgreSQLConnection])
  async init(): Promise<void> {
    this.repository = this.psql.connection.getRepository(EntityCategory);
    this.categoryMapRepository = this.psql.connection.getRepository(EntityCategoryMapping);
  }

  async getWithIdOrName(id: string): Promise<EntityCategory|null> {
    try {
      const where: FindOptionsWhere<EntityCategory>[] = [
        { name: id },
      ];
      if (uuidRegex.test(id)) {
        where.push({ id });
      }
      return this.repository.findOne({ where });
    } catch (error) {
      if (!error.code) {
        throw ERR_INTERNAL_SERVER(`Get entity category with id or name error: ${error.message}`);
      }
      throw error;
    }
  }

  async tagCategory(
    id: string,
    parentId: string,
    user: RequestUser,
  ): Promise<EntityCategoryMapping> {
    try {
      const category = await this.getWithIdOrName(id);
      if (!category) {
        throw new ERR_BAD_REQUEST('Category not found');
      }
      const parentCategory = await this.getWithIdOrName(parentId);
      if (!parentCategory) {
        throw new ERR_BAD_REQUEST('Parent category not found');
      }
      const now = new Date();
      const toBeEntity:Partial<EntityCategoryMapping> = {
        createdBy: user.id,
        createdAt: now,
        updatedBy: user.id,
        updatedAt: now,
        categoryId: category.id,
        parentCategoryId: parentCategory.id,
      };

      const entity = this.categoryMapRepository.create(toBeEntity);

      const createdEntity = await this.categoryMapRepository.save(entity);

      return createdEntity;
    } catch (error) {
      if (!error.code) {
        throw ERR_INTERNAL_SERVER(`Tag category error: ${error.message}`);
      }
      throw error;
    }
  }

  async search(
    query: EntityCategoryPaginationParamsDTO,
  ): Promise<[EntityCategory[], number, number]> {
    try {
      const limit = clamp(query.$limit ?? 10, 1, 1000);
      const skip = query.$page && query.$page > 1 ? (query.$page - 1) * limit : 0;
      const dbQuery = this.repository.createQueryBuilder('category');
      dbQuery.leftJoin('category.categories', 'parent');

      if (query.name && query.name.length > 0) {
        dbQuery.andWhere('category.name IN (:...name)', { name: query.name });
      }
      if (query.excludeId && query.excludeId.length > 0) {
        dbQuery.andWhere('category.id NOT IN (:...excludeId)', { excludeId: query.excludeId });
      }
      if (query.excludeName && query.excludeName.length > 0) {
        dbQuery.andWhere(
          'category.name NOT IN (:...excludeName)',
          { excludeName: query.excludeName },
        );
      }
      if (query.parentId && query.parentId.length > 0) {
        dbQuery.andWhere('parent.id IN (:...parentId)', { parentId: query.parentId });
      }
      if (query.parentName && query.parentName.length > 0) {
        dbQuery.andWhere('parent.name IN (:...parentName)', { parentName: query.parentName });
      }
      if (query.excludeParentId && query.excludeParentId.length > 0) {
        const tagQuery = this.categoryMapRepository.createQueryBuilder('tag');
        tagQuery.select('tag.categoryId');
        tagQuery.where(
          'tag.parentCategoryId IN (:...excludeParentId)',
          { excludeParentId: query.excludeParentId },
        );
        const [tagQueryString, queryParams] = tagQuery.getQueryAndParameters();
        dbQuery.andWhere(`category.id NOT IN (${tagQueryString})`, queryParams);
      }
      if (query.excludeParentOfId && ) {
      }
      if (query.search) {
        const { searchKey = ['name', 'label', 'description'] } = query;
        dbQuery.andWhere(
          new Brackets((qb) => {
            searchKey.forEach((key) => {
              qb.orWhere(`category.${key} ILIKE :search`, { search: `%${query.search}%` });
            });
          }),
        );
      }

      if (query.$order) {
        const orderKeyList = query.$order.split(',');
        const sortList = query.$sort ? query.$sort.split(',') : [];
        orderKeyList.forEach((key, index) => {
          dbQuery.addOrderBy(key, <'ASC' | 'DESC'>sortList[index] || 'ASC');
        });
      } else {
        dbQuery.orderBy('category.name', 'ASC');
      }

      dbQuery.skip(skip);
      dbQuery.take(limit);

      const [data, count] = await dbQuery.getManyAndCount();

      return [data, count, Math.ceil(count / limit)];
    } catch (error) {
      if (!error.code) {
        throw ERR_INTERNAL_SERVER(`Search entity category error: ${error.message}`);
      }
      throw error;
    }
  }
}

When I select copilot completion at this line it would cause segmentation fault

Image

When I select copilot completion at this line instead it doesn't cause segmentation fault
Image

Image

Relevant configuration

return {
  'saghen/blink.cmp',
  dependencies = {
    'rafamadriz/friendly-snippets',
    {
      dependencies = {
        {
          "zbirenbaum/copilot.lua",
          cmd = "Copilot",
          build = ":Copilot auth",
          event = "InsertEnter",
          opts = {
            suggestion = { enabled = false },
            panel = { enabled = false },
          },
        },
      },
      "giuxtaposition/blink-cmp-copilot",
    },
  },
  opts = {
    sources = {
      default = {
        'lsp',
        'path',
        'snippets',
        'buffer',
        'copilot',
      },
      providers = {
        copilot = {
          name = "copilot",
          module = "blink-cmp-copilot",
          score_offset = 100,
          async = true,
        },
      },
    },
  },
}

neovim version

0.10.2

blink.cmp version

1.3.1

@TzeroOcne TzeroOcne added the bug Something isn't working label May 16, 2025
@sabitm
Copy link

sabitm commented May 19, 2025

Related to this #1516?

@TzeroOcne
Copy link
Author

it might be, but now I cannot consistently reproduce it more after I renew my copilot subscription

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants