|
515 | 515 |
|
516 | 516 | # textDocument/didOpen - https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md#textDocument_didOpen |
517 | 517 | context 'given a textDocument/didOpen notification' do |
518 | | - let(:validation_result) { ['validation_result'] } |
519 | | - |
520 | | - shared_examples_for "an opened document with validation errors" do |file_uri, file_content| |
| 518 | + shared_examples_for "an opened document with enqueued validation" do |file_uri, file_content| |
521 | 519 | let(:notification_method) { 'textDocument/didOpen' } |
522 | 520 | let(:notification_params) { { |
523 | 521 | 'textDocument' => { |
|
533 | 531 | expect(subject.documents.document(file_uri)).to eq(file_content) |
534 | 532 | end |
535 | 533 |
|
536 | | - it 'should reply with diagnostic information on the file' do |
537 | | - expect(subject).to receive(:reply_diagnostics).with(file_uri,validation_result).and_return(true) |
538 | | - subject.receive_notification(notification_method, notification_params) |
539 | | - end |
540 | | - end |
541 | | - |
542 | | - shared_examples_for "an opened document with no validation errors" do |file_uri, file_content| |
543 | | - let(:notification_method) { 'textDocument/didOpen' } |
544 | | - let(:notification_params) { { |
545 | | - 'textDocument' => { |
546 | | - 'uri' => file_uri, |
547 | | - 'languageId' => 'puppet', |
548 | | - 'version' => 1, |
549 | | - 'text' => file_content, |
550 | | - } |
551 | | - }} |
552 | | - |
553 | | - it 'should add the document to the document store' do |
554 | | - subject.receive_notification(notification_method, notification_params) |
555 | | - expect(subject.documents.document(file_uri)).to eq(file_content) |
556 | | - end |
557 | | - |
558 | | - it 'should reply with empty diagnostic information on the file' do |
559 | | - expect(subject).to receive(:reply_diagnostics).with(file_uri,[]).and_return(true) |
| 534 | + it 'should enqueue the file for validation' do |
| 535 | + expect(PuppetLanguageServer::ValidationQueue).to receive(:enqueue).with(file_uri, 1, Object, Object) |
560 | 536 | subject.receive_notification(notification_method, notification_params) |
561 | 537 | end |
562 | 538 | end |
|
566 | 542 | end |
567 | 543 |
|
568 | 544 | context 'for a puppet manifest file' do |
569 | | - before(:each) do |
570 | | - expect(PuppetLanguageServer::DocumentValidator).to receive(:validate).and_return(validation_result) |
571 | | - allow(subject).to receive(:reply_diagnostics).and_return(true) |
572 | | - end |
573 | | - it_should_behave_like "an opened document with validation errors", MANIFEST_FILENAME, ERROR_CAUSING_FILE_CONTENT |
| 545 | + it_should_behave_like "an opened document with enqueued validation", MANIFEST_FILENAME, ERROR_CAUSING_FILE_CONTENT |
574 | 546 | end |
575 | 547 |
|
576 | 548 | context 'for a Puppetfile file' do |
577 | | - before(:each) do |
578 | | - allow(subject).to receive(:reply_diagnostics).and_return(true) |
579 | | - end |
580 | | - it_should_behave_like "an opened document with no validation errors", PUPPETFILE_FILENAME, ERROR_CAUSING_FILE_CONTENT |
| 549 | + it_should_behave_like "an opened document with enqueued validation", PUPPETFILE_FILENAME, ERROR_CAUSING_FILE_CONTENT |
581 | 550 | end |
582 | 551 |
|
583 | 552 | context 'for an EPP template file' do |
584 | | - before(:each) do |
585 | | - expect(PuppetLanguageServer::DocumentValidator).to receive(:validate_epp).and_return(validation_result) |
586 | | - allow(subject).to receive(:reply_diagnostics).and_return(true) |
587 | | - end |
588 | | - it_should_behave_like "an opened document with validation errors", EPP_FILENAME, ERROR_CAUSING_FILE_CONTENT |
| 553 | + it_should_behave_like "an opened document with enqueued validation", EPP_FILENAME, ERROR_CAUSING_FILE_CONTENT |
589 | 554 | end |
590 | 555 |
|
591 | 556 | context 'for an unknown file' do |
592 | | - before(:each) do |
593 | | - allow(subject).to receive(:reply_diagnostics).and_return(true) |
594 | | - end |
595 | | - it_should_behave_like "an opened document with no validation errors", UNKNOWN_FILENAME, ERROR_CAUSING_FILE_CONTENT |
| 557 | + it_should_behave_like "an opened document with enqueued validation", UNKNOWN_FILENAME, ERROR_CAUSING_FILE_CONTENT |
596 | 558 | end |
597 | 559 | end |
598 | 560 |
|
|
618 | 580 |
|
619 | 581 | # textDocument/didChange - https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md#didchangetextdocument-notification |
620 | 582 | context 'given a textDocument/didChange notification and a TextDocumentSyncKind of Full' do |
621 | | - let(:validation_result) { ['validation_result'] } |
622 | | - |
623 | | - shared_examples_for "a changed document with validation errors" do |file_uri, new_file_content| |
624 | | - let(:notification_params) { { |
625 | | - 'textDocument' => { |
626 | | - 'uri' => file_uri, |
627 | | - 'version' => 2, |
628 | | - }, |
629 | | - 'contentChanges' => [ |
630 | | - { |
631 | | - 'range' => nil, |
632 | | - 'rangeLength' => nil, |
633 | | - 'text' => new_file_content, |
634 | | - } |
635 | | - ] |
636 | | - }} |
637 | | - let(:notification_method) { 'textDocument/didChange' } |
638 | | - let(:new_file_content ) { 'new_file_content' } |
639 | | - |
640 | | - it 'should update the document in the document store' do |
641 | | - subject.receive_notification(notification_method, notification_params) |
642 | | - expect(subject.documents.document(file_uri)).to eq(new_file_content) |
643 | | - end |
644 | | - |
645 | | - it 'should reply with diagnostic information on the file' do |
646 | | - expect(subject).to receive(:reply_diagnostics).with(file_uri, validation_result).and_return(true) |
647 | | - subject.receive_notification(notification_method, notification_params) |
648 | | - end |
649 | | - end |
650 | | - |
651 | | - shared_examples_for "a changed document with no validation errors" do |file_uri, new_file_content| |
| 583 | + shared_examples_for "a changed document with enqueued validation" do |file_uri, new_file_content| |
652 | 584 | let(:notification_params) { { |
653 | 585 | 'textDocument' => { |
654 | 586 | 'uri' => file_uri, |
|
670 | 602 | expect(subject.documents.document(file_uri)).to eq(new_file_content) |
671 | 603 | end |
672 | 604 |
|
673 | | - it 'should reply with empty diagnostic information on the file' do |
674 | | - expect(subject).to receive(:reply_diagnostics).with(file_uri, []).and_return(true) |
| 605 | + it 'should enqueue the file for validation' do |
| 606 | + expect(PuppetLanguageServer::ValidationQueue).to receive(:enqueue).with(file_uri, 2, Object, Object) |
675 | 607 | subject.receive_notification(notification_method, notification_params) |
676 | 608 | end |
677 | 609 | end |
|
681 | 613 | end |
682 | 614 |
|
683 | 615 | context 'for a puppet manifest file' do |
684 | | - before(:each) do |
685 | | - expect(PuppetLanguageServer::DocumentValidator).to receive(:validate).and_return(validation_result) |
686 | | - allow(subject).to receive(:reply_diagnostics).and_return(true) |
687 | | - end |
688 | | - it_should_behave_like "a changed document with validation errors", MANIFEST_FILENAME, ERROR_CAUSING_FILE_CONTENT |
| 616 | + it_should_behave_like "a changed document with enqueued validation", MANIFEST_FILENAME, ERROR_CAUSING_FILE_CONTENT |
689 | 617 | end |
690 | 618 |
|
691 | 619 | context 'for a Puppetfile file' do |
692 | | - before(:each) do |
693 | | - allow(subject).to receive(:reply_diagnostics).and_return(true) |
694 | | - end |
695 | | - it_should_behave_like "a changed document with no validation errors", PUPPETFILE_FILENAME, ERROR_CAUSING_FILE_CONTENT |
| 620 | + it_should_behave_like "a changed document with enqueued validation", PUPPETFILE_FILENAME, ERROR_CAUSING_FILE_CONTENT |
696 | 621 | end |
697 | 622 |
|
698 | 623 | context 'for an EPP template file' do |
699 | | - before(:each) do |
700 | | - expect(PuppetLanguageServer::DocumentValidator).to receive(:validate_epp).and_return(validation_result) |
701 | | - allow(subject).to receive(:reply_diagnostics).and_return(true) |
702 | | - end |
703 | | - it_should_behave_like "a changed document with validation errors", EPP_FILENAME, ERROR_CAUSING_FILE_CONTENT |
| 624 | + it_should_behave_like "a changed document with enqueued validation", EPP_FILENAME, ERROR_CAUSING_FILE_CONTENT |
704 | 625 | end |
705 | 626 |
|
706 | 627 | context 'for a file the server does not understand' do |
707 | | - before(:each) do |
708 | | - expect(PuppetLanguageServer::DocumentValidator).to receive(:validate).exactly(0).times |
709 | | - allow(subject).to receive(:reply_diagnostics).and_return(true) |
710 | | - end |
711 | | - it_should_behave_like "a changed document with no validation errors", UNKNOWN_FILENAME, ERROR_CAUSING_FILE_CONTENT |
| 628 | + it_should_behave_like "a changed document with enqueued validation", UNKNOWN_FILENAME, ERROR_CAUSING_FILE_CONTENT |
712 | 629 | end |
713 | 630 | end |
714 | 631 |
|
|
0 commit comments