Skip to content

Commit

Permalink
vue: fix WEB-61727, WEB-63637, WEB-62930
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 091b6828076560b58cf5f9300715dba280f7259f
  • Loading branch information
anstarovoyt authored and intellij-monorepo-bot committed Nov 3, 2023
1 parent 279bda3 commit 167111e
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class AstroLspServerSupportProvider : LspServerSupportProvider {
}
}

class AstroLspServerDescriptor(project: Project) : JSFrameworkLspServerDescriptor(project, astroLspServerPackageDescriptor, "Astro") {
class AstroLspServerDescriptor(project: Project) : JSFrameworkLspServerDescriptor(project, AstroLspExecutableDownloader, "Astro") {
override fun isSupportedFile(file: VirtualFile): Boolean = isFileAcceptableForService(file)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,12 @@ import com.intellij.openapi.util.text.StringUtil
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.platform.lsp.util.convertMarkupContentToHtml
import com.intellij.psi.PsiFile
import com.intellij.util.text.SemVer
import org.eclipse.lsp4j.MarkupContent

class AstroLspTypeScriptService(project: Project) : BaseLspTypeScriptService(project, AstroLspServerSupportProvider::class.java) {
override val name = "Astro LSP"
override val prefix = "Astro"

override fun getServiceVersion(): SemVer {
return AstroLspExecutableDownloader.calculateVersion(project)
}

override fun createQuickInfoResponse(markupContent: MarkupContent): TypeScriptQuickInfoResponse {
return TypeScriptQuickInfoResponse().apply {
val content = HtmlBuilder().appendRaw(convertMarkupContentToHtml(markupContent)).toString()
Expand Down
1 change: 1 addition & 0 deletions vuejs/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
</extensionPoints>

<extensions defaultExtensionNs="com.intellij">
<registryKey defaultValue="1.8.22" description="Vue service version for downloading" key="vue.language.server.default.version"/>
<dependencySupport kind="javascript" coordinate="npm:vue" displayName="Vue.js"/>
<dependencySupport kind="javascript" coordinate="npm:nuxt" displayName="Nuxt"/>
<css.embeddedCssProvider implementation="org.jetbrains.vuejs.css.VueEmbeddedCssProvider"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.intellij.lang.typescript.lsp.JSFrameworkLspServerDescriptor
import com.intellij.lang.typescript.lsp.LspServerDownloader
import com.intellij.lang.typescript.lsp.LspServerPackageDescriptor
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.registry.Registry
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.platform.lsp.api.LspServerSupportProvider
import com.intellij.platform.lsp.api.LspServerSupportProvider.LspServerStarter
Expand All @@ -14,9 +15,11 @@ import org.jetbrains.vuejs.lang.typescript.service.isVolarEnabledAndAvailable
import org.jetbrains.vuejs.lang.typescript.service.isVolarFileTypeAcceptable
import org.jetbrains.vuejs.options.getVueSettings

val volarLspServerPackageDescriptor = LspServerPackageDescriptor("@vue/language-server",
"1.8.2",
"/bin/vue-language-server.js")
val volarLspServerPackageDescriptor: () -> LspServerPackageDescriptor = {
LspServerPackageDescriptor("@vue/language-server",
Registry.stringValue("vue.language.server.default.version"),
"/bin/vue-language-server.js")
}

class VolarSupportProvider : LspServerSupportProvider {
override fun fileOpened(project: Project, file: VirtualFile, serverStarter: LspServerStarter) {
Expand All @@ -26,12 +29,12 @@ class VolarSupportProvider : LspServerSupportProvider {
}
}

class VolarServerDescriptor(project: Project) : JSFrameworkLspServerDescriptor(project, volarLspServerPackageDescriptor, "Vue") {
class VolarServerDescriptor(project: Project) : JSFrameworkLspServerDescriptor(project, VolarExecutableDownloader, "Vue") {
override fun isSupportedFile(file: VirtualFile): Boolean = isVolarFileTypeAcceptable(file)
}

@ApiStatus.Experimental
object VolarExecutableDownloader : LspServerDownloader(volarLspServerPackageDescriptor) {
object VolarExecutableDownloader : LspServerDownloader(volarLspServerPackageDescriptor()) {
override fun getSelectedPackageRef(project: Project): NodePackageRef {
return getVueSettings(project).packageRef
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import com.intellij.openapi.util.text.StringUtil
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.platform.lsp.util.convertMarkupContentToHtml
import com.intellij.psi.PsiFile
import com.intellij.util.text.SemVer
import org.eclipse.lsp4j.MarkupContent
import org.jetbrains.vuejs.VueBundle
import org.jetbrains.vuejs.lang.typescript.service.isVolarEnabledAndAvailable
Expand All @@ -23,10 +22,6 @@ class VolarTypeScriptService(project: Project) : BaseLspTypeScriptService(projec
override val prefix: String
get() = VueBundle.message("vue.service.prefix")

override fun getServiceVersion(): SemVer {
return VolarExecutableDownloader.calculateVersion(project)
}

override fun createQuickInfoResponse(markupContent: MarkupContent): TypeScriptQuickInfoResponse {
return TypeScriptQuickInfoResponse().apply {
val content = HtmlBuilder().appendRaw(convertMarkupContentToHtml(markupContent)).toString()
Expand Down
2 changes: 1 addition & 1 deletion vuejs/src/org/jetbrains/vuejs/options/VueSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class VueSettings(val project: Project) : SimplePersistentStateComponent<VueSett
}

var packageRef
get() = createPackageRef(state.packageName, volarLspServerPackageDescriptor.serverPackage)
get() = createPackageRef(state.packageName, volarLspServerPackageDescriptor().serverPackage)
set(value) {
val refText = extractRefText(value)
val changed = state.packageName != refText
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import com.intellij.lang.javascript.typescript.service.TypeScriptServiceTestBase
import com.intellij.lang.typescript.compiler.TypeScriptCompilerSettings
import com.intellij.openapi.Disposable
import com.intellij.platform.lsp.tests.checkLspHighlighting
import com.intellij.util.text.SemVer
import junit.framework.TestCase
import org.jetbrains.vuejs.lang.VueInspectionsProvider
import org.jetbrains.vuejs.lang.VueTestModule
import org.jetbrains.vuejs.lang.configureVueDependencies
import org.jetbrains.vuejs.options.getVueSettings
import org.junit.Test

class VolarServiceTest : VolarServiceTestBase() {
Expand Down Expand Up @@ -212,6 +214,40 @@ class VolarServiceTest : VolarServiceTestBase() {
assertHasServiceItems(elements, true)
}

@Test
fun testSimpleCustomVersionVue() {
myFixture.enableInspections(VueInspectionsProvider())
val version = SemVer.parseFromText("1.8.10")
myFixture.configureVueDependencies(VueTestModule.VUE_3_0_0, additionalDependencies = mapOf("@vue/language-server" to version.toString()))
myFixture.configureByText("tsconfig.json", tsconfig)
performNpmInstallForPackageJson("package.json")
val state = getVueSettings(project).state
val old = state.packageName
disposeOnTearDown(Disposable { state.packageName = old })
val path = myFixture.findFileInTempDir("node_modules/@vue/language-server").path
TestCase.assertNotNull(path)
state.packageName = path

myFixture.configureByText("Simple.vue", """
<script setup lang="ts">
let <error descr="Vue: Type 'number' is not assignable to type 'string'.">a</error>: string = 1;
function acceptNumber(num: number): number { return num; }
acceptNumber(<error descr="Vue: Argument of type 'boolean' is not assignable to parameter of type 'number'.">true</error>);
</script>
<template>
<div v-text="acceptNumber(<error descr="Vue: Argument of type 'boolean' is not assignable to parameter of type 'number'.">true</error>)" />
<!-- todo remove duplicate internal warning -->
<div>{{acceptNumber(<error descr="Argument type true is not assignable to parameter type number"><error descr="Vue: Argument of type 'boolean' is not assignable to parameter of type 'number'.">true</error></error>)}}</div>
</template>
""")
myFixture.checkLspHighlighting()

assertCorrectService(version)
}

private fun getPresentationTexts(elements: Array<LookupElement>): List<String?> {
return elements.map { element ->
val presentation = LookupElementPresentation()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.intellij.lang.javascript.library.typings.TypeScriptExternalDefinition
import com.intellij.lang.typescript.compiler.languageService.TypeScriptLanguageServiceUtil
import com.intellij.lang.typescript.library.download.TypeScriptDefinitionFilesDirectory
import com.intellij.openapi.util.Disposer
import com.intellij.util.text.SemVer
import org.jetbrains.vuejs.lang.typescript.service.volar.VolarExecutableDownloader
import org.jetbrains.vuejs.lang.typescript.service.volar.VolarTypeScriptService
import org.jetbrains.vuejs.options.VueServiceSettings
Expand Down Expand Up @@ -38,7 +39,7 @@ abstract class VolarServiceTestBase : BaseLspTypeScriptServiceTest() {
ensureServerDownloaded(VolarExecutableDownloader)
}

protected fun assertCorrectService() {
assertCorrectServiceImpl<VolarTypeScriptService>()
protected fun assertCorrectService(version: SemVer? = null) {
assertCorrectServiceImpl<VolarTypeScriptService>(version)
}
}

0 comments on commit 167111e

Please sign in to comment.