Skip to content

Completions should be prevented for single-line comments #2016

@dalyIsaac

Description

@dalyIsaac

Langium version: 4.0.0
Package name: langium

Original discussion: #2015

Steps To Reproduce

  1. Create a grammar with a single-line comment as a hidden terminal
  2. Create a completion provider
  3. Start typing after a single-line comment has started

Link to code example: https://github.com/TypeFox/monaco-languageclient/blob/main/packages/examples/src/langium/statemachine/ls/statemachine.langium

Link to example: https://langium.org/showcase/statemachine/

The current behavior

Completions are currently possible within single-line comments.

image

The expected behavior

Completions should be able to be disabled within single-line comments.

There are currently tests for multi-line comments, but not for single-line comments:

test('Can perform completion for fully qualified names', async () => {
const grammar = `
grammar FQNCompletionTest
entry Model:
(persons+=Person | greetings+=Greeting)*;
Person:
'person' name=FQN;
Greeting:
'Hello' person=[Person:FQN] '!';
FQN returns string: ID ('.' ID)*;
hidden terminal WS: /\\s+/;
terminal ID: /[_a-zA-Z][\\w_]*/;
hidden terminal ML_COMMENT: /\\/\\*[\\s\\S]*?\\*\\//;
`;
const services = await createServicesForGrammar({ grammar });
const completion = expectCompletion(services);
const text = `
person John.Miller
person John.Smith.Junior
person John.Smith.Senior
Hello <|>John<|>.Smi<|>th.Jun<|>ior
Hello <|>John./* Hello */ <|>Miller
`;
await completion({
text: text,
index: 0,
expectedItems: [
'John.Miller',
'John.Smith.Junior',
'John.Smith.Senior'
]
});
await completion({
text: text,
index: 1,
expectedItems: [
'John.Miller',
'John.Smith.Junior',
'John.Smith.Senior'
]
});
await completion({
text: text,
index: 2,
expectedItems: [
'John.Smith.Junior',
'John.Smith.Senior'
]
});
await completion({
text: text,
index: 3,
expectedItems: [
'John.Smith.Junior'
]
});
await completion({
text: text,
index: 4,
expectedItems: [
'John.Miller',
'John.Smith.Junior',
'John.Smith.Senior'
]
});
// A comment within the FQN should prevent any completion from appearing
await completion({
text: text,
index: 5,
expectedItems: []
});
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    completionCompletion related issue

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions