Skip to content

Commit

Permalink
fix(indentation): hover behavior when indentation not set
Browse files Browse the repository at this point in the history
The previous behavior of hover replaces indentations with the  
entity, because Markdown treats whitespace at the beginning of a line
in a special way. However, when the indentation setting wasn't set, the
regex that does that replace was set to empty ("") and so would include
an   entity between every character.

Signed-off-by: Kasama <robertoaall@gmail.com>
  • Loading branch information
Kasama committed Mar 27, 2023
1 parent 762209c commit c7b8877
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/languageservice/services/yamlHover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class YAMLHover {
const regex = new RegExp(this.indentation, 'g');
const markupContent: MarkupContent = {
kind: MarkupKind.Markdown,
value: contents.replace(regex, '&emsp;'),
value: this.indentation ? contents.replace(regex, '&emsp;') : contents,
};
const result: Hover = {
contents: markupContent,
Expand Down
34 changes: 25 additions & 9 deletions test/hover.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,10 @@ describe('Hover Tests', () => {
let telemetry: TestTelemetry;

before(() => {
languageSettingsSetup = new ServiceSetup()
.withHover()
.withIndentation(' ')
.withSchemaFileMatch({
uri: 'http://google.com',
fileMatch: ['bad-schema.yaml'],
});
languageSettingsSetup = new ServiceSetup().withHover().withSchemaFileMatch({
uri: 'http://google.com',
fileMatch: ['bad-schema.yaml'],
});
const {
languageService: langService,
languageHandler: langHandler,
Expand Down Expand Up @@ -65,7 +62,7 @@ describe('Hover Tests', () => {
});
}

describe('Hover', function () {
describe('Hover', function() {
it('Hover on key on root', async () => {
languageService.addSchema(SCHEMA_ID, {
type: 'object',
Expand Down Expand Up @@ -513,7 +510,26 @@ users:
);
});

it('hover on value and its description has multiline, indentationa and special string', async () => {
it('hover on value and its description has multiline, indentation and special string', async () => {
(() => {
languageSettingsSetup = new ServiceSetup()
.withHover()
.withIndentation(' ')
.withSchemaFileMatch({
uri: 'http://google.com',
fileMatch: ['bad-schema.yaml'],
});
const {
languageService: langService,
languageHandler: langHandler,
yamlSettings: settings,
telemetry: testTelemetry,
} = setupLanguageService(languageSettingsSetup.languageSettings);
languageService = langService;
languageHandler = langHandler;
yamlSettings = settings;
telemetry = testTelemetry;
})();
//https://github.com/redhat-developer/vscode-yaml/issues/886
languageService.addSchema(SCHEMA_ID, {
type: 'object',
Expand Down
1 change: 0 additions & 1 deletion test/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ describe('Kubernetes Integration Tests', () => {
const fileMatch = ['*.yml', '*.yaml'];
languageSettingsSetup = new ServiceSetup()
.withHover()
.withIndentation(' ')
.withValidate()
.withCompletion()
.withSchemaFileMatch({
Expand Down

0 comments on commit c7b8877

Please sign in to comment.