Remove language service dependency on TextDocuments (#742)
The code actions API depends on `TextDocuments`. This is specific to the language server. This makes it hard to use without a language server. The use of `TextDocuments` has been removed. Instead, the resolved text document is passed down.master
parent
33f94bae1a
commit
ae18cb2449
|
@ -412,7 +412,6 @@ async function createProjectService(
|
||||||
diagnosticRelatedInformation: true,
|
diagnosticRelatedInformation: true,
|
||||||
itemDefaults,
|
itemDefaults,
|
||||||
},
|
},
|
||||||
documents: documentService.documents,
|
|
||||||
getConfiguration,
|
getConfiguration,
|
||||||
getDocumentSymbols: (uri: string) => {
|
getDocumentSymbols: (uri: string) => {
|
||||||
return connection.sendRequest('@/tailwindCSS/getDocumentSymbols', { uri })
|
return connection.sendRequest('@/tailwindCSS/getDocumentSymbols', { uri })
|
||||||
|
@ -1171,7 +1170,7 @@ async function createProjectService(
|
||||||
if (!document) return null
|
if (!document) return null
|
||||||
let settings = await state.editor.getConfiguration(document.uri)
|
let settings = await state.editor.getConfiguration(document.uri)
|
||||||
if (!settings.tailwindCSS.codeActions) return null
|
if (!settings.tailwindCSS.codeActions) return null
|
||||||
return doCodeActions(state, params)
|
return doCodeActions(state, params, document)
|
||||||
}, null)
|
}, null)
|
||||||
},
|
},
|
||||||
onDocumentLinks(params: DocumentLinkParams): DocumentLink[] {
|
onDocumentLinks(params: DocumentLinkParams): DocumentLink[] {
|
||||||
|
|
|
@ -17,13 +17,14 @@ import { flatten, dedupeBy } from '../util/array'
|
||||||
import { provideCssConflictCodeActions } from './provideCssConflictCodeActions'
|
import { provideCssConflictCodeActions } from './provideCssConflictCodeActions'
|
||||||
import { provideInvalidApplyCodeActions } from './provideInvalidApplyCodeActions'
|
import { provideInvalidApplyCodeActions } from './provideInvalidApplyCodeActions'
|
||||||
import { provideSuggestionCodeActions } from './provideSuggestionCodeActions'
|
import { provideSuggestionCodeActions } from './provideSuggestionCodeActions'
|
||||||
|
import { TextDocument } from 'vscode-languageserver-textdocument'
|
||||||
|
|
||||||
async function getDiagnosticsFromCodeActionParams(
|
async function getDiagnosticsFromCodeActionParams(
|
||||||
state: State,
|
state: State,
|
||||||
params: CodeActionParams,
|
params: CodeActionParams,
|
||||||
|
document: TextDocument,
|
||||||
only?: DiagnosticKind[]
|
only?: DiagnosticKind[]
|
||||||
): Promise<AugmentedDiagnostic[]> {
|
): Promise<AugmentedDiagnostic[]> {
|
||||||
let document = state.editor.documents.get(params.textDocument.uri)
|
|
||||||
if (!document) return []
|
if (!document) return []
|
||||||
let diagnostics = await doValidate(state, document, only)
|
let diagnostics = await doValidate(state, document, only)
|
||||||
|
|
||||||
|
@ -40,7 +41,7 @@ async function getDiagnosticsFromCodeActionParams(
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function doCodeActions(state: State, params: CodeActionParams): Promise<CodeAction[]> {
|
export async function doCodeActions(state: State, params: CodeActionParams, document: TextDocument): Promise<CodeAction[]> {
|
||||||
if (!state.enabled) {
|
if (!state.enabled) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
@ -48,6 +49,7 @@ export async function doCodeActions(state: State, params: CodeActionParams): Pro
|
||||||
let diagnostics = await getDiagnosticsFromCodeActionParams(
|
let diagnostics = await getDiagnosticsFromCodeActionParams(
|
||||||
state,
|
state,
|
||||||
params,
|
params,
|
||||||
|
document,
|
||||||
params.context.diagnostics
|
params.context.diagnostics
|
||||||
.map((diagnostic) => diagnostic.code)
|
.map((diagnostic) => diagnostic.code)
|
||||||
.filter(Boolean) as DiagnosticKind[]
|
.filter(Boolean) as DiagnosticKind[]
|
||||||
|
@ -56,7 +58,7 @@ export async function doCodeActions(state: State, params: CodeActionParams): Pro
|
||||||
return Promise.all(
|
return Promise.all(
|
||||||
diagnostics.map((diagnostic) => {
|
diagnostics.map((diagnostic) => {
|
||||||
if (isInvalidApplyDiagnostic(diagnostic)) {
|
if (isInvalidApplyDiagnostic(diagnostic)) {
|
||||||
return provideInvalidApplyCodeActions(state, params, diagnostic)
|
return provideInvalidApplyCodeActions(state, document, diagnostic)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isCssConflictDiagnostic(diagnostic)) {
|
if (isCssConflictDiagnostic(diagnostic)) {
|
||||||
|
|
|
@ -18,13 +18,13 @@ import { dset } from 'dset'
|
||||||
import selectorParser from 'postcss-selector-parser'
|
import selectorParser from 'postcss-selector-parser'
|
||||||
import { flatten } from '../util/array'
|
import { flatten } from '../util/array'
|
||||||
import { getTextWithoutComments } from '../util/doc'
|
import { getTextWithoutComments } from '../util/doc'
|
||||||
|
import { TextDocument } from 'vscode-languageserver-textdocument'
|
||||||
|
|
||||||
export async function provideInvalidApplyCodeActions(
|
export async function provideInvalidApplyCodeActions(
|
||||||
state: State,
|
state: State,
|
||||||
params: CodeActionParams,
|
document: TextDocument,
|
||||||
diagnostic: InvalidApplyDiagnostic
|
diagnostic: InvalidApplyDiagnostic
|
||||||
): Promise<CodeAction[]> {
|
): Promise<CodeAction[]> {
|
||||||
let document = state.editor.documents.get(params.textDocument.uri)
|
|
||||||
if (!document) return []
|
if (!document) return []
|
||||||
let documentText = getTextWithoutComments(document, 'css')
|
let documentText = getTextWithoutComments(document, 'css')
|
||||||
let cssRange: Range
|
let cssRange: Range
|
||||||
|
@ -144,7 +144,7 @@ export async function provideInvalidApplyCodeActions(
|
||||||
diagnostics: [diagnostic],
|
diagnostics: [diagnostic],
|
||||||
edit: {
|
edit: {
|
||||||
changes: {
|
changes: {
|
||||||
[params.textDocument.uri]: changes,
|
[document.uri]: changes,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -20,7 +20,6 @@ export type ClassNames = {
|
||||||
export type EditorState = {
|
export type EditorState = {
|
||||||
connection: Connection
|
connection: Connection
|
||||||
folder: string
|
folder: string
|
||||||
documents: TextDocuments<TextDocument>
|
|
||||||
userLanguages: Record<string, string>
|
userLanguages: Record<string, string>
|
||||||
capabilities: {
|
capabilities: {
|
||||||
configuration: boolean
|
configuration: boolean
|
||||||
|
|
Loading…
Reference in New Issue